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






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,IfPassed) VALUES (1,1,55,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (1,2,73,0);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (2,3,44,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (1,4,55,1);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (1,5,73,0);
INSERT INTO Exam (StudentID,ExamID,Mark,IfPassed) VALUES (2,6,44,1);

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








Related examples in the same category

1.Use DISTINCT to get non-dupliate records
2.Use DISTICNT to get unique value
3.Eliminating Duplicate Data Using DISTINCT 1
4.Select distinct records using JOIN
5.The SQL key word DISTINCT has the effect that equivalent data records are output only once.
6.DISTINCT works with multiple-column output too.
7.how many different drivers there are, use COUNT(DISTINCT)
8.DISTINCT with two columns
9.DISTINCT works with expressions, not just column values.
10.Inserting name values into the multisequence table generates separate sequences for each distinct name:
11.Count distinct
12.Distinct sub string
13.Average distinct value
14.Return a list of surnames, with each surname appearing only once?
15.The fraction of the records that contain unique or non-unique names: