Reputation: 1457
I have the following table - order:
Currently using the following query:
select `id`
from `order`
where `userid_FK`=24242 and `productid_FK`=5
which returns - 32, 33, 34
How can I also select max(price) 197.0000 in one query is this possible (the max price for that user and productid)?
Thanks
Upvotes: 0
Views: 35
Reputation: 3540
you need to use MAX
.
This will give you max price with one row.
select `id`,max(price)
from `order`
where `userid_FK`=24242 and `productid_FK`=5
If you want with all records:
select `id`,(select max(price)
from `order`
where `userid_FK`=24242 and `productid_FK`=5) ) as maxrate
from `order`
where `userid_FK`=24242 and `productid_FK`=5
Upvotes: 1
Reputation: 42783
One way is using subquery in select list
select `id`, (select max(price) from `order` where `userid_FK`=24242 and `productid_FK`=5) as maxprice
from `order`
where `userid_FK`=24242 and `productid_FK`=5
Upvotes: 1