I’ll try to give an “eBay” example, I’m sure it will be the easiest way to ask this.
Imagine a table of bids:
bid_id | bid_from_user | bid_for_auction | bid_price
1 | 150 | 1 | 20
2 | 453 | 1 | 30
3 | 42 | 1 | 50
4 | 12 | 2 | 12
5 | 60 | 2 | 20
Imagine you need to list auctions which a certain person is currently bidding on and losing.
Therefore, our current user ID is 12, so bid_from_user='12'
This user is currently bidding on auction id 2 with price 12 and is obviously losing, as there is another user bidding on the same auction with a higher price.
I don’t want to list all the auctions the user is bidding on, I just want to list those the user is bidding on and losing (= not the ones he’s winning).
So, what query do I run to do this?
Edit: The above would seem to be the cleanest, most legible solution; but here is an alternative in allowance for MySQL traditionally not handling subqueries well…