Britech College | Resources

UPDATES, SOURCE CODES AND LECTURE NOTES

SQL JOINING

create database dbABCorp

create table tblcustomers
(
cid int primary key,
cname varchar (50),
caddress varchar (50),
cgender varchar (50),
)

create table tblproducts
(
pid int primary key,
pname varchar (50),
price float,
quantity int,
)

create table tblorders
(
orid int primary key,
orno int,
cid int foreign key references tblcustomers (cid),
pid int foreign key references tblproducts (pid),
quantity int,
total float,
)

select * from tblorders


insert into tblcustomers values (1,'Remo','Cebu','Male')
insert into tblcustomers values (2,'Jake','Cebu','Male')


insert into tblproducts values (1,'TV',12000,10)
insert into tblproducts values (2,'CELLPHONE',8000,10)
insert into tblproducts values (3,'FAN',1000,10)

select * from tblorders
insert into tblorders (orid,orno,cid,pid,quantity) values  (1,1,1,2,2)

select orid,orno,tblorders.cid,tblcustomers.cname,tblorders.pid,tblproducts.pname,tblproducts.price,tblorders.quantity,(tblorders.quantity*tblproducts.price) as 'Total Amount' from tblorders 
inner join tblcustomers on tblcustomers.cid=tblorders.cid
inner join tblproducts on tblproducts.pid=tblorders.pid

insert into tblorders (orid,orno,cid,pid,quantity) values  (2,2,3,2,2)




No comments :

Post a Comment