Sorting Data : Sort Order : Select Clause SQL / MySQL


SQL / MySQL » Select Clause » Sort Order »

 

Sorting Data



/*

mysql> SELECT StudentID,ExamID,Mark,IfPassed FROM Exam
    -> ORDER BY Mark ASC;
+-----------+--------+------+----------+
| StudentID | ExamID | Mark | IfPassed |
+-----------+--------+------+----------+
|         2 |      3 |   44 |        1 |
|         1 |      1 |   55 |        1 |
|         1 |      2 |   73 |        0 |
+-----------+--------+------+----------+
3 rows in set (0.00 sec)


*/

/* Prepare the data */  
Drop TABLE Exam;

CREATE TABLE Exam (
   StudentID  INT NOT NULL,
   ExamID     INT NOT NULL,
   Mark       INT,
   IfPassed   SMALLINT
)TYPE = InnoDB;

/* Insert data for testing */
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (1,1,55,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (1,2,73,0);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (2,3,44,1);

/* Real command */
  
SELECT StudentID,ExamID,Mark,IfPassed FROM Exam
ORDER BY Mark ASC;

           
       



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

SQL / MySQL

 Navioo Select Clause
» Sort Order