0% found this document useful (0 votes)
7 views

SQL 3

The document discusses SQL queries using subqueries and joins on tables containing student and department data. Various queries are performed to select, filter, order and join data from the tables.

Uploaded by

appathangam.2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

SQL 3

The document discusses SQL queries using subqueries and joins on tables containing student and department data. Various queries are performed to select, filter, order and join data from the tables.

Uploaded by

appathangam.2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SUBQUERIES AND JOINS

SHAVYA S S
71762303114

SQL> CREATE TABLE Dept(dept VARCHAR(5),hodname VARCHAR(10));


Table created.
SQL> insert into dept values ('EEE','X'); 1
row created.
SQL> insert into dept values ('ECE','Y'); 1
row created.
SQL> insert into dept values ('CSE','Z'); 1
row created.
SQL> select * from Dept; DEPT

HODNAME

EEE X
ECE Y
CSE Z

SQL> create table stud(sno NUMBER(3),studid NUMBER(3),name CHAR(10),Dept


CHAR(3),sec CHAR(2),sub1 NUMBER(3),sub2 NUMBER(3),CGPA NUMBER(5));
Table created.
SQL> insert into stud values (1,65,'Varun','EEE','I',98,99,9.87); 1
row created.
SQL> insert into stud values (2,66,'Nithya','EEE','I',98,99,9.87); 1
row created.
SQL> insert into stud values (3,67,'Santhosh','EEE','II',89,90,7.70); 1
row created.
SQL> insert into stud values (4,68,'Priya','EEE','I',94,95,9.01); 1 row
created.
SQL> insert into stud values (5,69,'Reena','EEE','II',90,95,8.89); 1 row
created.
SQL> select * from stud;
SNO STUDID NAME DEP SE SUB1 SUB2 CGPA

1 65 Varun EEE I 98 99 10
2 66 Nithya EEE I 98 99 10
3 67 Santhosh EEE II 89 90 8
4 68 Priya EEE I 94 95 9
5 69 Reena EEE II 90 95 9
SQL> select * from stud where sec='I';
SNO STUDID NAME DEP SE SUB1 SUB2 CGPA

1 65 Varun EEE I 98 99 10
2 66 Nithya EEE I 98 99 10
4 68 Priya EEE I 94 95 9
SQL> select name,CGPA from stud where sec='II'order by CGPA;
NAME CGPA

Santhosh 8
Reena 9
SQL> select name from stud where CGPA>8; NAME

Varun
Nithya
Priya
Reena
SQL> select sno,name,dept,hodname from stud,Dept where stud.dept = dept.deptname;
SNO NAME DEP HODNAME

1 Varun EEE X
2 Nithya EEE X
3 Santhosh EEE X
4 Priya EEE X
5 Reena EEE X
SQL> insert into stud values (6,70,'Rockey','EEE','II',60,56,6.89); 1 row
created.
SQL> select * from stud;
SNO STUDID NAME DEP SE SUB1 SUB2 CGPA

1 65 Varun EEE I 98 99 10
2 66 Nithya EEE I 98 99 10
3 67 Santhosh EEE II 89 90 8
4 68 Priya EEE I 94 95 9
5 69 Reena EEE II 90 95 9
6 70 Rockey EEE II 60 56 7

6 rows selected.
SQL> insert into stud values (7,71,'Saanu','EEE','II',60,56,6.19); 1 row
created.
SQL> select * from stud;
SNO STUDID NAME DEP SE SUB1 SUB2 CGPA

1 65 Varun EEE I 98 99 10
2 66 Nithya EEE I 98 99 10
3 67 Santhosh EEE II 89 90 8
4 68 Priya EEE I 94 95 9
5 69 Reena EEE II 90 95 9
6 70 Rockey EEE II 60 56 7
7 71 Saanu EEE II 60 56 6

7 rows selected.
SQL> select studid,hodname from stud,dept where stud.cgpa<7 and stud.dept=dept.deptname;
STUDID HODNAME

71 X

SQL> drop table stud;


Table dropped.
SQL> drop table dept;
Table dropped.

You might also like