Top Menu

Search This Blog

SQL ORDER BY Keyword

If you want the data to appear in a specific order you need to use the “order by” keyword.

Syntax:


SELECT column_1_name, column_2_name, .....
FROM table_name
ORDER BY column_1_name ASC|DESC

Syntax for ORDER BY Several Columns:

SELECT column_1_name, column_2_name, .....
FROM table_name
ORDER BY column_1_name ASC|DESC, column_2_name ASC|DESC

As you see, we have like this "Candidate" table.












Example:

The following SQL syntax selects all candidate from the "Candidate" table, sorted by Ascending Order the "Postcode" column.


   SELECT * FROM CANDIDATE
   ORDER BY PostCode

Output:











The following SQL syntax selects all candidate from the "Candidate" table, sorted by DESCENDING Order the "Postcode" column. 

 SELECT * FROM CANDIDATE
 ORDER BY PostCode DESC


Output:











The following SQL syntax selects all candidate from the "Candidate" table, sorted by Ascending Order the "Postcode" and "CandidateNumber" column. 

  SELECT * FROM CANDIDATE
  ORDER BY PostCode,CandidateNumber

Output:


Post a Comment

Designed by OddThemes | Distributed By Gooyaabi Templates