简体   繁体   中英

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?

这将为您提供独特的price

SELECT * FROM  (SELECT COUNT(price) pricecount, price FROM groceries GROUP BY price) a WHERE a.pricecount = 1;

Try this one

SELECT price
FROM groceries
GROUP BY price
HAVING COUNT(*) = 1

Select value from table group by value having count (value)=1

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM