0% found this document useful (0 votes)
12 views

Practical Programs from Mysql

Uploaded by

tomkbiju2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Practical Programs from Mysql

Uploaded by

tomkbiju2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Practical Programs from Mysql

19) Consider the following tables BOOKS and ISSUE. Write SQL commands for
the statements (i) to (iv) and give outputs for SQL queries (v) to (vi)

Table : Books

BOOK ID Bookname Authorname Publisher Price Qty


LO1 MATHS RAMAN ABC 70 20
LO2 SCIENCE AGARKAR DEF 90 15
LO3 SOCIAL SURESH XYZ 85 30
LO4 COMPUTE JOHN ZEROWAIT 75 7
R
LO5 TELUGU NANNAYA DEF 60 25
LO6 ENGLISH WORDS DEF 55 12

Table : Issues
BOOK _ID QTY_ISSUED
LO2 13
LO4 5
LO5 21

i) To show Book name, Author name and price of books of ABC publisher
SELECT BOOKNAME,AUTHORNAME,PRICE FROM BOOKS
WHERE PUBLISHER=’ABC’;

ii)To display the details of the books in descending order of their price.
SELECT * FROM BOOKS ORDER BY PRICE DESC;

iii) To decrease the qty_issued from ISSUES table by 3 (all rows must
decrease)
UPDATE ISSUES SET QTY_ISSUED=QTY_ISSUED-3;

iv) To display the total no. of records exist in a table Book


SELECT COUNT(*) FROM BOOKS;

v) SELECT publisher,min(price) FROM BOOKS GROUP BY publisher;


PUBLISHER MIN(PRICE)
ABC 70
DEF 55
XYS 85
ZEROWAIT 75
vi) SELECT price from BOOKS,ISSUES where
BOOKS.BOOK_ID=ISSUES.BOOK_ID AND QTY_ISSUED=5;
PRICE
75

2) Consider the following tables BOOKS and ISSUE. Write SQL commands for
the statements (i) to (iv) and give outputs for SQL queries (v) to (vi)

Table : FACULTY

F_ID FNAME LNAME HIRE_DATE SALARY


102 AMIT MISHRA 12-10-1998 12000
103 NITIN VYAS 24-12-1994 8000
104 RAKSHIT SONI 18-05-2001 14000
105 RASHMI MALHOTRA 11-09-2004 11000
106 SULEKA SRIVASTAV 05-06-2006 10000

Table : COURSES

C_ID F_ID CNAME FEES


C21 102 Grid computing 40000
C22 106 System Design 16000
C23 104 Computer Security 8000
C24 106 Human Biology 15000
C25 102 Computer Network 20000
C26 105 Visual Basic 6000

i) To display details of those Faculties whose salary is greater than 12000.


SELECT * FROM FACULTY WHERE SALARY>12000;

ii) To display the details of courses whose fees is in the range of 15000 to
50000 (both values included).
SELECT * FROM COURSES
WHERE FEES BETWEEN 15000 AND 50000;

iii) To increase the fees of all courses by 500 of “System Design” Course.
UPDATE COURSES SET FEES=FEES+500
WHERE CNAME=’System Design’;
iv) To display details of those courses which are taught by ‘Sulekha’ in
descending order of courses.
SELECT * FROM FACULTY F,COURSES C
WHERE F.F_ID=C.F_ID ORDER BY CNAME DESC;

v) Select COUNT(DISTINCT F_ID) from COURSES;


COUNT(DISTINCT F_ID)

102
103
104
105
106

vi) Select F_ID,MIN(FEES) from FACULTY,COURSES


GROUP BY F_ID;
F_ID MIN(FEES)
102 20000
104 8000
105 6000
106 15000

You might also like