You are on page 1of 2

Experiment No - 4

AIM - To study group by and order by commands.

THEORY

 Group by - used to group different types of categories.


 Order by - used to order or arrange the following table in ascending order or
descending or in some specified order.

STEPS
1. CREATE TABLE stu(sno number(1), name char(10), rollnum number(3) branch char(5));

2. INSERT INTO stu(sno,name,rollnum,branch) values (‘1’, ‘abc’, ‘123’, ‘ECE’);


SQL> CREATE TABLE stu(sno number(1), name char(10), rollnum number(3) branch char(5));

Table created.

SQL> INSERT INTO stu(sno,name,rollnum,branch) values (‘1’, ‘abc’, ‘123’, ‘ECE’);

1 row created.

SQL> SELECT * from stu;

SNO NAME ROLLNUM BRANCH


----- ----------- ---------- ---------
1 abc 123 ECE

3. INSERT INTO stu(sno,name,rollnum,branch) values (‘3’, ‘def’, ‘072’, ‘ECE’);

4. INSERT INTO stu(sno,name,rollnum,branch) values (‘2’, ‘mno’, ‘121’, ‘ECE’);

5. INSERT INTO stu(sno,name,rollnum,branch) values (‘5’, ‘pqr’, ‘303’, ‘CSE’);

6. INSERT INTO stu(sno,name,rollnum,branch) values (‘4’, ‘xyz’, ‘304’, ‘CSE’);

7. INSERT INTO stu(sno,name,rollnum,branch) values (‘6’, ‘tuv’, ‘110’, ‘CSE’);


8. SELECT * FROM stu;

SNO NAME ROLLNUM BRANCH


----- ----------- ---------- ---------
1 abc 123 ECE
3 def 072 ECE
2 mno 121 ECE
5 pqr 303 CSE
4 xyz 304 CSE
6 tuv 110 CSE

9. SELECT * FROM stu ORDER BY sno;


SNO NAME ROLLNUM BRANCH
----- ----------- ---------- ---------
1 abc 123 ECE
2 mno 121 ECE
3 def 072 ECE
4 xyz 304 CSE
5 pqr 303 CSE
6 tuv 110 CSE

10. SELECT branch FROM stu GROUP BY branch;


Branch
----------
CSE
ECE

You might also like