MySQL + SQL · Lesson 50
DISTINCT, Alias and ORDER BY
DISTINCT — Unique Rows
SELECT DISTINCT class FROM students;Removes duplicate values from the result.
Alias — Rename in Output
SELECT name AS student_name, marks AS score
FROM students;AS gives a column a friendlier name in the result (does not change the table).
ORDER BY — Sorting
SELECT name, marks FROM students ORDER BY marks DESC;
SELECT name FROM students ORDER BY name ASC;DESC = high to low, ASC = low to high (default).
Summary
- DISTINCT removes duplicates; AS renames output columns.
- ORDER BY sorts: ASC (default) or DESC.