I am building an auction system. And I am in the process that will display every bid transaction that a user has. In my table view I want to show if a certain bid transaction is the highest bid and I want to identify also if there is a higher bid than the user's bid.
Here's my query:
SELECT
pb.id AS bid_id,
pb.product_id AS product_id,
pb.bidding_date AS bidding_date,
MAX(bidding_price) AS bidding_price
FROM auction_product_bidding AS pb
LEFT JOIN auction_product AS p
ON(pb.product_id = p.id)
WHERE pb.user_id = 1
AND p.datetime_end > NOW()
AND p.`status` = 0
GROUP BY pb.product_id;
In this query I can get the last bid of a certain user.
+--------+------------+---------------------+---------------+
| bid_id | product_id | bidding_date | bidding_price |
+--------+------------+---------------------+---------------+
| 55 | 4 | 2016-08-01 11:50:51 | 118000.00 |
| 74 | 13 | 2016-08-11 14:14:25 | 202.00 |
+--------+------------+---------------------+---------------+
I want to add another column beside bidding price that will identify if there's a much more higher bid.
If the user has the highest bid I want to add a status like 'First Place' and if there is a much more higher bid it will display 'Bid Again'
Is it possible in a query? I read about control flow but I don't know if I can use this. If not possible maybe I will do this on the PHP side.
Thats all I hope you can help me.
MAXon bidding_price, or a user can make several bids, but then you are just showing one of the user's bids (bid_id,bidding_date) arbitrarily chosen.