0

My db table looks like this

BID_Id  UL_Id   AUC_Id  AI_Id   BID_Amount  BID_Status  BID_Date    
1       2       50      53      800         1           2015-06-24 12:26:51 
2       4       50      53      860         1           2015-06-24 12:28:03
3       2       50      53      920         1           2015-06-24 12:26:51 
4       4       50      53      1000        1           2015-06-24 12:28:03

Here UL_Id 2 is my value and i other person is 4. So the maximum amount i have bid is 920 and the other person bid is 1000. So i need to find out that if any person has bid greater than me get that value else retrieve my maximum value only. I hope its clear now guys.

If my record is greater, I want to retrieve that value also.

rahul
  • 841
  • 1
  • 8
  • 18
  • possible duplicate of [How to get the max of two values in MySQL?](http://stackoverflow.com/questions/1565688/how-to-get-the-max-of-two-values-in-mysql) – Nikolay Kostov Jun 24 '15 at 07:41
  • Here my maximum value is 80000, i need to find out that anyone else has put a value more that 80000 in that value, if not retrieve my maximum value. – rahul Jun 24 '15 at 07:43
  • Do you want to get the maximum record from your table ? – Noman Jun 24 '15 at 07:49
  • i think you should really invest a little more time clarifying what your problem is. Making it easier to understand would most likely greatly increase the chance of someone taking the time to think up a useful answer. – Burki Jun 24 '15 at 07:49
  • i have tried like this: SELECT BID_Amount FROM `bids` WHERE BID_Amount IN ( SELECT MAX( `BID_Amount` ) FROM `bids` WHERE UL_Id=4 AND `BID_Amount` > (SELECT MAX( `BID_Amount` ) FROM `bids` WHERE UL_Id !=4 ) ) – rahul Jun 24 '15 at 07:51
  • no noman, i want to find out the maximum value greater than my added maximum value in the table. if my maximum value is the greatest in that table retrieve my maximum value. – rahul Jun 24 '15 at 07:53
  • Fetch `MAX(BID_Amount)` from the table. If some one else has inserted another value, you'll get that and if not you'll get your value. – Prerak Sola Jun 24 '15 at 07:56
  • Step back a bit. Forget what you think you want to get. are you looking to insert a row so that the new row has the next higher id – Drew Jun 24 '15 at 07:57
  • Cuz if u get max it can be stale data 1 sec later – Drew Jun 24 '15 at 07:58
  • you simply need this query `SELECT MAX( BID_Amount ) FROM bids` it will give you only maximum record from your table . – Noman Jun 24 '15 at 08:01
  • Great norman then what – Drew Jun 24 '15 at 08:02

1 Answers1

0

Make an include for your db, for example this:

<?php
$link = mysql_connect('localhost', 'YourUser', 'YourPassword');
if (!$link) {
   die ('Error: ' . mysql_error());
}
// DB select
$db_selected = mysql_select_db('DBName', $link);
?>

After make a simple .php page like this:

<?php
$query = mysql_query ("SELECT MAX(BID_Amount) as MAX FROM bids");
while($result = mysql_fetch_array($query))
{
 $maxvalue = $result['MAX'];
}
// Echo the max value
echo "The max value is: $maxvalue";
?>
Andrea php
  • 63
  • 2
  • 8
  • This is not what exactly i want. I want a maximum bid amount from that table, if i have a bid amount in the table, and that is the maximum amount that i have put. and i'm finding any other person who has put a maximum amount than mine. if not so retrieve my maximum amount. its little bit tough to understand but. – rahul Jun 24 '15 at 12:32
  • Ah ok. You need two or more table when people do a bid, you safe the code of the bid and the amount in a second table. When people do another bid you see if this bis is big than the last bid in the second table. If the asnwers is yes, you make an UPDATE TABLE, and you set the new highest bid. – Andrea php Jun 24 '15 at 14:25
  • the bid is done by ajax call as fast as it is. Every 2 seconds the bid is refreshed. I dont want to create a relational database. One table thats it calling is very fast. Two table comparison very slow. I hope im right ' – rahul Jun 26 '15 at 09:53
  • Please check the question once more. I have updated for better understanding. – rahul Jun 26 '15 at 11:51