You are on page 1of 8

Assignment of final term exams:

Name: Farhan Ahmad


Roll No: 1020
Class: BS (IT)
Semester: 5th
Section: B
Shift: Morning
Course :Web Engineering
Assignment Submitted To:
Sir Ali Imran
Assignment of final term exams:

SQL joins:
Join clause is used to join rows from two or more tables, based on a related column between
them.

Different types of SQL join:


 INNER JOIN
 LEFT (OUTER) JOIN
 RIGHT (OUTER) JOIN
 Left outer join
 Natural join
 equal join
 cross join
 right outer join

INNER JOIN:
Returns records that have matching values in both tables.

The INNER JOIN keyword selects all records that have matching values in both tables.

LEFR (OUTER) JOIN:


Returns all records from the left table, and the matched records from the right table.

The result is NULL if from right side, there is no match.

RIGHT (OUTER) JOIN:


Returns all records from the right table, and the matched records from the left table.

The result is NULL if from left side, there is no match.

Queries:

Create database information;

Use information;

Create table customers(cid int(2),cname varchar(20),ccell varchar(11));


Insert into customers(cid,cname,ccell) values(1,”Farhan”,030200039);

Insert into customers(cid,cname,ccell) values(2,”shahbaz anwar”,03022849);


Assignment of final term exams:

Insert into customers(cid,cname,ccell) values(3.”Faisal khalil”,030456639);

Insert into customers(cid,cname,ccell) values(5,”muzamil”,03039409);

Select * from customers;

Create table orderz(oid int(2),oamount int(15),cid varchar(20));


Insert into orderz(oid,oamount,cid) values(1,2999,1);

Insert into orderz(oid,oamount,cid) values(2,15000,2);

Insert into orderz(oid,oamount,cid) values(4,7899,3);

Insert into orderz(oid,oamount,cid) values(3,2500,5);

Select * from orderz;

Join:
Select* from customers

Join orderz

On customers.cid=orderz.cid;

Left join:
Select customers.cid,cname,oamount

From customers

Left join orderz

On customers.cid=orderz.cid;

Right join:
Select customers.cid,cname,oamount

From customers

Right join orderz

On customers.cid=orderz.cid;

Natural join:
select * from customers natural join orderz;
Assignment of final term exams:

Left outer join:


select * from customers left outer join orderz on customers.cid=orderz.cid;

Right outer join:


select * from customers right outer join orderz on customers.cid=orderz.cid;

Cross join:
select * from customers cross join orderz;

Equal join:
select * from customers,orderz;

Practice screen shots are here attached:


Assignment of final term exams:
Assignment of final term exams:
Assignment of final term exams:
Assignment of final term exams:

You might also like