1/8
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
DISTINCT
Removes duplicate rows from a query result. Example: SELECT DISTINCT major returns each major once.
SELECT DISTINCT syntax
SELECT DISTINCT column_name FROM table_name;
DISTINCT example
SELECT DISTINCT academic_year FROM Students_Spring2024; Returns Freshman, Sophomore, Junior, and Senior once each.
DISTINCT with two columns
Returns unique combinations of all selected fields. Example: SELECT DISTINCT academic_year, major FROM Students_Spring2024;
DISTINCT and multiple columns
If either selected value differs, the row stays. Example: Freshman + Finance and Freshman + Marketing are different rows.
COUNT(DISTINCT column)
Counts unique non-NULL values. Example: SELECT COUNT(DISTINCT major) AS NumMajors FROM Students_Fall2024;
COUNT without DISTINCT
Counts every non-NULL value, including repeats. Example: COUNT(major) counts every student’s major entry.
DISTINCT vs. UNION
DISTINCT removes duplicates within one query result; UNION combines two query results and removes duplicate rows.
When not to use DISTINCT
Do not use it just to hide a bad JOIN; first make sure the JOIN conditions are correct.