Page 261 - PYTHON-12
P. 261
Resultant table: student
Name Rollno DOB Marks
Raj Kumar 1. 17-Nov-2000 93
Deep Singh 2. 22-Aug-1996 98
Ankit Sharma 3. 02-Feb-2000 76
Radhika Gupta 4. 03-Dec-1999 78
Payal Goel 5. 21-April-1998 82
Diksha Sharma 6. 17-Dec-1999 80
Gurpreet Kaur 7. 04-Jan-2000 65
Akshay Dureja 8. 05-May-1997 90
Shreya Anand 9. 08-Oct-1999 70
Prateek Mittal 10. 25-Dec-2000 75
10 rows in a set (0.02 sec)
CTM: The order in which the columns are displayed using the SELECT command is in accordance with the
order in which they are actually stored in the table.
2. Eliminating Duplicate/Redundant Data—DISTINCT clause
DISTINCT clause is used to remove duplicate rows from the results of a SELECT statement. It is
used to retrieve only unique values for a column in the table. The DISTINCT keyword can be used
only once with a given SELECT statement.
Syntax: SELECT DISTINCT <column-name> from <table-name>;
For example,
Suppose we have added a new column Stream to the table student:
Resultant table: student
Rollno Name Gender Marks DOB Mobile_no Stream
1. Raj Kumar M 93 17-Nov-2000 9586774748 Science
2. Deep Singh M 98 22-Aug-1996 8988886577 Commerce
3. Ankit Sharma M 76 02-Feb-2000 NULL Science
4. Radhika Gupta F 78 03-Dec-1999 9818675444 Humanities
5. Payal Goel F 82 21-April-1998 9845639990 Vocational
6. Diksha Sharma F 80 17-Dec-1999 9897666650 Humanities
7. Gurpreet Kaur F NULL 04-Jan-2000 7560567890 Science
8. Akshay Dureja M 90 05-May-1997 9560567890 Commerce
9. Shreya Anand F 70 08-Oct-1999 NULL Vocational
10. Prateek Mittal M 75 25-Dec-2000 9999967543 Science
10 rows in a set (0.02 sec) Resultant table: student
Stream Science displayed 4 times
With reference to the above table, if we
Science
write the SELECT statement as:
Commerce
SELECT Stream from student; Science
this statement shall return all the tuples Humanities
for field Stream from table student. It Vocational
will return duplicate values also. Thus, Humanities
in order to remove these duplicate Science Relational Database and SQL
values, DISTINCT clause is used. Commerce
Now, we write a query for displaying Vocational
the distinct contents on the basis of the Science
field Stream from student table: 10 rows in a set (0.02 sec)
12.31