Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views8 pages

SQL 1

Uploaded by

pranjulpandey006
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 views8 pages

SQL 1

Uploaded by

pranjulpandey006
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/ 8

Table:Books

Book Book Author


Publishers Price Type Qty
ID Name Name
C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
William
F0001 The Tears First Publ. 650 Fiction 20
Hopkins
F0002 Thunderbolts Anna Roberts First Publ. 750 Fiction 10
Brian and
T0001 My First C++ EPB 350 Text 15
Brooke

C++
T0002 A.W.Rossaine TDH 350 Text 50
Brainworks

Table:Issued

Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
1. To show Book name,Author name and Price of
books of First Publ. Publishers.

Ans - mysql> SELECT Book_Name,Author_Name,Price


-> from books
-> where Publishers="First Publ.";

Price Book_Name Author_Name


750 Thunderbolts Anna Roberts
650 The Tears William Hopkins
2. To list the names from books of Text type.

Ans - mysql> SELECT Book_Name


-> from books
-> WHERE Type="Text";

Book_Name
My First C++

C++ Brainworks
3. To display the names and price from books
in ascending order of their price.

Ans - mysql> SELECT Book_Name,Price


-> from books
-> ORDER BY Price;

Book_Name Price
My First C++ 350
C++ Brainworks 350
Fast Cook 355
The Tears 650
Thunderbolts 750
4. To increase the price of all the books of
EPB Publishers by 50.

Ans - mysql> UPDATE books


-> SET Price=Price+50
-> WHERE Publishers="EPB";

Author
Book ID Book Name Publishers Price Type
Name
C0001 Fast Cook Lata Kapoor EPB 405 Cookery
William
F0001 The Tears First Publ. 650 Fiction
Hopkins

F0002 Thunderbolts Anna Roberts First Publ. 750 Fiction

Brian and
T0001 My First C++ EPB 400 Text
Brooke

T0002 C++ Brainworks A.W.Rossaine TDH 350 Text


5. To display the Book_Id, Book_Name and
Quantity_Issued for all books which have
been issued. ( The query will require
contents from both the tables. )

Ans - mysql> SELECT books.Book_Id ,


-> Book_Name,Quantity_Issued
-> FROM Books,Issued
-> WHERE books.Book_Id=Issued.Book_Id;

Book_Id Book_Name Quantity_Issued


T0001 My First C++ 4
C0001 Fast Cook 5
F0001 The Tears 2
6. To insert a new row in the table Issued
having the following data: “F0003”,1

Ans - mysql> INSERT INTO issued


-> values("F0003",1);

Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
F0003 1
7. Give the output of the follwing queries
based on the above tables:

I. SELECT COUNT(*) FROM Books;

Ans - Count(*)
5

II. SELECT MAX(Price) FROM Books WHERE Qty>=15;

Ans - MAX(Price)
750

III. SELECT Book_Name,Author_Name FROM Books


WHERE Publishers = “EPB”;

Ans - Book_Name Author_Name


Fast Cook Lata Kapoor
My First C++ Brian and Brooke

IV.SELECT COUNT (DISTINCT Publishers) FROM Books


WHERE Price >= 400;

Ans - COUNT(DISTINCT Publishers)


3

You might also like