Class 12 | MySQL 11

To display unique/distinct records

Command: Distinct clause
Helps us to eliminate duplicate records while displaying the details

Roll    Name    age
101    Aaa      10
102    Bbb      12
101    Aaa      10
103    Aaa      14
104    Ccc      15
101    Aaa      10
105    Eee      15

Example:1
Select * from std;
All the records will be displayed

Example:2
Select distinct * from std;
Roll Name age
101 Aaa 10
102 Bbb 12
103 Aaa 14
104 Ccc 15
105 Eee 15

Example:3
Select distinct roll from std;
101
102
103
104
105

Example:4
Select distinct name from std;
Aaa
Bbb
Ccc
Eee

To display the record in proper order

Command: Order by clause
Helps us to display the records in a particular order

By default, the records are displayed in ascending order. In order to display the records in descending order, we have to use “desc” clause.

Select * from std order by roll;
Select * from std order by name;
Select * from std order by name, roll;

If required two or more columns can be used along with order by clause. The records are firstly arranged according to first column. And the records which have same value of the first column are arranged according to the second column and so on.

Using desc clause

Select * from std order by roll desc;
Select * from std order by name desc;