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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp