Eliminating Duplicate Data Using DISTINCT 2 : Distinct : Select Clause SQL / MySQL


SQL / MySQL » Select Clause » Distinct »

 

Eliminating Duplicate Data Using DISTINCT 2



/*
mysql> SELECT DISTINCT Mark, ExamID FROM Exam;
+------+--------+
| Mark | ExamID |
+------+--------+
|   55 |      1 |
|   73 |      2 |
|   44 |      3 |
|   55 |      4 |
|   73 |      5 |
|   44 |      6 |
+------+--------+
6 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);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (1,4,55,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (1,5,73,0);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassedVALUES (2,6,44,1);

/* Real command */
SELECT DISTINCT Mark, ExamID FROM Exam;
           
       



Leave a Comment / Note


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

Follow Navioo On Twitter

SQL / MySQL

 Navioo Select Clause
» Distinct