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 ?
05 Jun 2020 at 04:01 PM
0give a positive ratinggive a negative ratingshow 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 ;
21 Jun 2020 at 02:34 PM
0give a positive ratinggive a negative ratingshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook
2022 AnswerTabsTermsContact us