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 ?
0
give a positive ratinggive a negative rating
05 Jun 2020 at 04:01 PM
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 ;
0
give a positive ratinggive a negative rating
21 Jun 2020 at 02:34 PM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us