You are on page 1of 5

SQL Queries

Q13.
Q14. Create a Database LIBRARY.
1. Create a table BOOKs (book_id (PK), book_name, author_name,
publishers, price, type, qty)
2. Create a table ISSUED (issue_id, book_id (FK), quantity_issued )

Answer to be written on white page


Create Table Command:
Create table books (book_id varchar(20) primary key,
book_name varchar(20),author_name varchar(20),publishers
varchar(20), price int,type varchar(20),qty int);

Create table issued (book_id varchar(20), quantity_issued int , foreign


key(book_id) references books(bool_id);
Write the SQL queries –
i. To show Book name, Author name and Price of books of First Publ.
publishers.
select Book_name,Author_name, price from books where
Publishers =”EPB”;
ii. To list the names from books of Text type.
Select Book_name from books where type=”Text”;
iii. To display the names and price from books in ascending order.
Select Book_name, price from books order by price desc;
iv. To increase the price of all books of EPB publishers by 50.
update books set price= price+50 where publishers = “EPB”;
v. To display the Book_Id, Book_Name. and Quantity_Issued for all
books which have been issued.
Select Book_ID, Book_Name, Quantity_Issued from Books,Issued
where Books.Book_Id=Issued.Book_Id;
Write the Output of the following queries based on the above tables
i. SELECT COUNT(*) FROM BOOKS;

Count(*)
5
ii. SELECT MAX(PRICE) FROM BOOKS WHERE QUANTITY >=
15;
Max(price)

750`

iii. SELECT BOOK_NAME, AUTHOR_NAME FROM BOOKS


WHERE PUBLISHERS = “EPB”;
Book_name Author_name
Fast cook Latha Kapoor
My first c++ Brian & Brooke
iv. SELECT COUNT(DISTINCT PUBLISHERS) FROM BOOKS WHERE
PRICE >= 400;
Q15. Write the MYSQL Connectivity program in Python to
a. Create a database school
b. Create a table student with the specifications- Roll no integer, Name
Char (10), city char (20), dob varchar /in MYSQL and perform the
following operation.

c. SELECT COUNT (*), CITY FROM STUDENT GROUP BY CITY


HAVING COUNT (*)>1;

Output

(2, 'Chennai')
(3, 'Kolkata')
Q16. Integrate SQL with python by importing the MYSQL module
a. SELECTMAX (DOB), MIN (DOB) FROM STUDENT;
Ans:

Output
('12may23', '11apr23')

You might also like