Reputation: 219
I want to display dishname
and dishprice
with DISTINCT
value of 2nd highest dishprice
.
What is the problem with the following query?
SELECT dishName, DISTINCT(dishPrice) FROM `tblDish` ORDER BY dishPrice LIMIT 1,1
Upvotes: 1
Views: 75
Reputation: 39
use GROUP BY with the query. So, you can list and differentiate with their categories.
Upvotes: 1
Reputation: 6361
Do it like this
SELECT DISTINCT(dishPrice), dishName FROM `tblDish` GROUP BY `dishPrice` ORDER BY `dishPrice` LIMIT 1,1
You should always mention Distinction before selecting any other column of the table
Upvotes: 1
Reputation: 28755
In case there are more then one record for same price then need to group them bye price and group concat all the records
SELECT GROUP_CONCAT(dishName), dishPrice FROM `tblDish` GROUP BY dishPrice ORDER BY dishPrice DESC LIMIT 1,1
Upvotes: 3