You are on page 1of 7

create table students(stud_id int primary key, branch varchar(30),class varchar(30),gender varchar(30));

drop table students;

insert into students values(100,'CSE','TY','male');

insert into students values(101,'Mech','FY','female');

insert into students values(102,'Civil','SY','male');

insert into students values(103,'Biotech','Btech','male');

insert into students values(104,'ETC','TY','female');

insert into students values(105,'cse','TY','female');

insert into students values(106,'entc','TY','male');

insert into students values(107,'mech','TY','female');

insert into students values(108,'civil','TY','male');


select * from students;

create table library(lib_id int,stud_id int,book_name varchar(50),issue_date varchar(20),return_date


varchar(20),foreign key(stud_id) references students(stud_id));

insert into library values(100,100,'Maths','10/11/22','15/11/22');

insert into library values(102,102,'Physics','09/07/22','15/07/22');

insert into library values(103,103,'Biology','08/02/22','15/02/22');


insert into library values(104,104,'History','23/09/22','5/10/22');

alter table library add no_of_books int;

insert into library values (105, 105,'c programming','12/11/22','17/11/22',2);

insert into library values (105, 105,'java programming','13/11/22','18/11/22',1);

insert into library values (105, 105,'c++ programming','14/11/22','19/11/22',1);

insert into library values (105, 105,'web development','15/11/22','20/11/22',3);

insert into library values (105, 105,'php fundamentals','16/11/22','21/11/22',2);


update library set no_of_books = 1 where lib_id =100;

update library set no_of_books = 2 where lib_id =101;

update library set no_of_books = 2 where lib_id =102;

update library set no_of_books = 3 where lib_id =103;

update library set no_of_books = 4 where lib_id =104;

select * from library;


select sum(no_of_books) as total_books_taken,

min(no_of_books) as min_books_taken,

max(no_of_books) as max_books_taken,

avg(no_of_books) as avg_books_taken from library;

select * from library order by book_name asc;


SELECT COUNT(no_of_books), book_name

FROM library

GROUP BY book_name;

select students.stud_id,library.lib_id,library.issue_date

from students

inner join library on students.stud_id=library.lib_id;

Select * from students

left join library on students.stud_id=library.lib_id;


Select * from students

right join library on students.stud_id=library.lib_id;

You might also like