Академический Документы
Профессиональный Документы
Культура Документы
S.No.. EXERCISES
1 Based on Joins:
Job select * from duty;
+------+-----------+
+------+------------+ | id | task |
| id | title | +------+-----------+
+------+------------+ | 1 | Test |
| 1 | Tester | | 2 | Calculate |
| 2 | Accountant | | 3 | Program |
| 3 | Developer | | 4 | Test |
| 4 | Coder | | 5 | Manage |
| 5 | Director | | 6 | Talk |
| 6 | Mediator | | 7 | Speak |
| 7 | Proffessor | | 8 | Shout |
| 8 | Programmer | | 9 | Walk |
| 9 | Developer +------+-----------+
Equi join:
1) Display employee first name, job and title and there should be no redundancy.
2) Display employee first name, job and title, task and there should be no redundancy.
Left join:
1) Retrieve first name, last name and title of the job having all the rows of employee
table.
2) Retrieve first name, last name and title of the job of coders even if the employee
corresponding to job title doesn’t exist, null should be displayed.
3) Retrieve first name, last name and task of coders even if the employee corresponding
to job title doesn’t exist, null should be displayed.
Right join:
1) Retrieve first name, last name and title of the job having all the rows of job table.
Self Join:
Create the table emp with attributes: empno, ename, mgrno, hire_date
1) Write a query to list out the names of the manager with the employee record one.
2) Write a query to list all employees who joined the company before their manager.
select * from Authors;
+--------+--------+--------+--------+
| AuthID | AuthFN | AuthMN | AuthLN |
+--------+--------+--------+--------+
| 1006 | H | S. | T |
| 1007 | J | C | O |
| 1008 | B | NULL | E |
| 1009 | R | M | R |
| 1010 | J | K | T |
| 1011 | J | G. | N |
| 1012 | A | NULL | P |
| 1013 | A | NULL | W |
| 1014 | N | NULL | A |
+--------+--------+--------+--------+
select * from Books;
+--------+----------------+-----------+
| BookID | BookTitle | Copyright |
+--------+----------------+-----------+
| 12786 | Java | 1934 |
| 13331 | MySQL | 1919 |
| 14356 | PHP | 1966 |
| 15729 | PERL | 1932 |
| 16284 | Oracle | 1996 |
| 17695 | Pl/SQL | 1980 |
| 19264 | JavaScript | 1992 |
| 19354 | www.java2s.com | 1993 |
+--------+----------------+-----------+
select * from AuthorBook;
+--------+--------+
| AuthID | BookID |
+--------+--------+
| 1009 | 12786 |
| 1006 | 14356 |
| 1008 | 15729 |
| 1011 | 15729 |
| 1014 | 16284 |
| 1010 | 17695 |
| 1012 | 19264 |
| 1012 | 19354 |
+--------+--------+
CROSS JOINS:-
1) Display author id corresponding to book title bt it shud be one to many relationship.
2) Display book’s title copyright,authors last name,fisrt name,middlename of the entries
having copyright after 1980 in ascending order.
3) Display first name ,last name and title of the job corresponding to every name.
2.
BASED ON VIEWS
(j) Create view vw_books on table Books renaming the column booktitle as title and
display it.
(l) Update the field title in view vw_books with value “sqlserver” where bookid=13331
(n) Create view on table employee with fields start date and salary and display it.
3 BASED ON INDEXES
4 BASED ON SUB-QUERIES
1.Create the table Client with attributes: C_ID ,Name, City and Create the table Product with
attributes:Prod_ID , Prod_Detail , C_ID , price
a) Write a query to list of clients that are available in Products table.
b) Write a query to list of clients that are not available in Products table
2.Create the table address with attributes: First Name, Last Name, Street Address and Zip
Code of the members of your mailing list;
Create another table zipcode with attributes: City, State and Zip Code.
Write a query to find the names of the members of your mailing list who live in Georgia.
(g) Wap for inserting the record and then selecting the record.
(h) Wap to find the category of the employee and then inserting it into a table.
(i) Wap to create a procedure using while loop.
(j) WAP to create a function by using IF-ELSE statement
(k) WAP to create a procedure by using CASE condition
(l) WAP to create a procedure by using REPEAT-UNTIL statement