truffle truffle - 10 months ago 63
MySQL Question

How to select only unique values from a table column in mysql. NOT using DISTINCT

I'm looking for something other than DISTINCT because with distinct you would return $2.90, $4.78, $1.99. $6.22 with the given column below in a table (let's say table groceries).

SELECT DISTINCT price
FROM groceries


For example if the whole price column has values:

price:

$2.90
$4.78
$1.99
$6.22
$1.99
$2.90


I just want the values that are unique only. So the return would be:
$4.78
$6.22

How can I do this with not using unique keys and also DISTINCT?

Answer Source

Try this one

SELECT price
FROM groceries
GROUP BY price
HAVING COUNT(*) = 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download