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.
💻 Live Code Editor
This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.