Select or count rows with unique values in column in table - SQL

How can I get or count only the rows with unique values in a specific column in table, by using SQL function SELECT FROM ?
posted on 05.06.2020 at 16:01
0pnshow more
onefiveonefive
Hi,

There are more solutions available to get the unique values from the table. It depends on your needs.

This will get unique values from the specific column, because of DISTINCT command:
SELECT DISTINCT brand FROM products ;
This will get other values related to unique values in the specific column, because of GROUP command:
SELECT id, brand FROM products GROUP by brand ;
This will count the values related to unique values in the specific column:
SELECT COUNT(quantity), brand FROM products GROUP by brand ;
This will get only the rows with unique value in the specific column, because of GROUP and HAVING:
SELECT COUNT(quantity), brand FROM products GROUP BY brand HAVING COUNT(quantity) = 1 ;
posted on 21.06.2020 at 14:34
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.