only those records which satisfy a given condition. For example in the student table, to display the list of students of age18 and above in alphabetical order of their names, the command is given as below: SELECT * FROM Student WHERE Age>= ORDER BY Name; Admno Name Gender Age Place Abinandh M Chennai Adarsh M Delhi Ayush M Delhi Devika F Bangalore Revathi F Chennai To display the list of students in the descending order of names of those students of age and above the command is given as : SELECT * FROM Student WHERE Age>= ORDER BY Name DESC; 12th Computer Chapter - - Admno Name Gender Age Place Revathi F Chennai Devika F Bangalore Ayush M Delhi Adarsh M Delhi Abinandh M Chennai Sorting can be done on multiple fields. Note . .
. GROUP BY clause The GROUP BY clause is used with the SELECT statement to group the students on rows or columns having identical values or divide the table in to groups. For example to know the number of male students or female students of a class, the GROUP BY clause may be used. It is mostly used in conjunction with aggregate functions to produce summary reports from the database.
The syntax for the GROUP BY clause is SELECT <column-names> FROM <table-name> GROUP BY <column-name>HAVING condition]; To apply the above command on the student table : SELECT Gender FROM Student GROUP BY Gender; The following command will give the below given result: Gender M F The point to be noted is that only two results have been returned. This is because we only have two gender types ‘Male’ and ‘Female’. The GROUP BY clause grouped all the ‘M’ students together and returned only a single row for it. It did the same with the ‘F’ students.
For example to count the number of male and female students in the student table, the following command is given : 12th Computer Chapter