Queries2

214 views
188 views

Published on

queries...

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
214
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Queries2

  1. 1. ---------------------------------------------------------15 SQL QUERIES:---------------------------------------------------------1)Names of Customer who have ordered items from dept having DID=D00001select CNAME from customer1 CID IN(select CID from cust_dept1 where DID=D00001);O/P:CNAME--------------------BhartiEna2 rows selected.2)Find the type of books in which Tina is interestedselect BOOK_NAME from books1 where DID IN (Select DID from cust_dept1 where CID IN(Select CIDfrom customer1 where CNAME=Tina));O/P:BOOK_NAME
  2. 2. --------------------biographyfiction2 rows selected.3)Type of Clothing selected by Nehalselect CLOTH_NAME from clothing1 where DID IN (Select DID from cust_dept1 where CID IN(Select CIDfrom customer1 where CNAME=Nehal));O/P:CLOTH_NAME--------------------FormalsTraditionalJeans1 row selected.4)Customers who dont stay in Mumbai and Delhiselect CNAME from customer where CADDRESS NOT IN(Mumbai,Delhi);O/P:
  3. 3. CNAME--------------------EnaNehal2 rows selected.5)Customers who are interested in TV whose inches are in the range of 30select CNAME from customer where CID IN (Select CID from cust_dept where DID IN(Select DID fromelectronics where ENAME=TV and EID IN(Select EID from TV where inches like(3%))));O/P:CNAME--------------------BhartiEna2 rows selected.6)Mobile having bluetooth connectivityselect * from mobile where connectivity like (B%);
  4. 4. O/P:CONNECTIVITY EID-------------------- ----------Bluetooth E00001Bluetooth E000012 rows selected.7)Customers whose name end with naselect CID,CNAME from customer where CNAME like (%na);O/P:CID CNAME---------- --------------------C00002 EnaC00004 KrinaC00005 Tina3 rows selected.8)Items belonging to Electronics department
  5. 5. select ENAME from electronics where Exists(Select DID from cust_dept whereelectronics.DID=cust_dept.DID ) ;O/P:ENAME--------------------MOBILEcamerasTV3 rows selected.9)Details of Items pressent in mobile section of Electronics departmentSelect * from electronics e ,mobile m where e.EID=m.EID;O/P:EID ENAME ECOST DID CONNECTIVITY EID---------- -------------------- ---------- ---------- -------------------- ----------E00001 MOBILE 10000 D00001 Bluetooth E00001E00001 MOBILE 10000 D00001 Infrared E00001E00001 MOBILE 10000 D00001 Bluetooth E000013 rows selected.
  6. 6. 10)Ascending orderselect * from customer order by CNAME;O/P:CID CNAME CADDRESS---------- -------------------- ------------------------------C00001 Bharti MumbaiC00002 Ena PuneC00004 Krina DelhiC00003 Nehal BangloreC00005 Tina Mumbai5 rows selected.11)Descending Orderselect * from customer order by CNAME desc;O/P:CID CNAME CADDRESS---------- -------------------- ------------------------------
  7. 7. C00005 Tina MumbaiC00003 Nehal BangloreC00004 Krina DelhiC00002 Ena PuneC00001 Bharti Mumbai5 rows selected.12)Details about which customers interested in which department (use of using clause)select CID,c.CNAME,c.CADDRESS,d.DID from customer c join cust_dept d using (CID);O/P:CID CNAME CADDRESS DID---------- -------------------- ------------------------------ ----------C00001 Bharti Mumbai D00001C00002 Ena Pune D00001C00003 Nehal Banglore D00002C00004 Krina Delhi D00002C00005 Tina Mumbai D000035 rows selected.13)Customers interested in mobiles having connectivity=bluetooth
  8. 8. select * from customer where CID in (Select CID from cust_dept where DID in (Select DID fromelectronics where EID in(Select EID from mobile where connectivity=Bluetooth)));O/P:CID CNAME CADDRESS---------- -------------------- ------------------------------C00001 Bharti MumbaiC00002 Ena Pune2 rows selected.14)Customers interested in biography section of books departmentselect * from customer where CID in (Select CID from cust_dept where DID in (Select DID from bookswhere BOOK_ID in (Select BOOK_ID from biography where TYPE=Freedom Fighter)));O/P:CID CNAME CADDRESS---------- -------------------- ------------------------------C00005 Tina Mumbai
  9. 9. 1 row selected.15)Electronic items having cost > 10000select * from electronics where ECOST > 10000O/P:EID ENAME ECOST DID---------- -------------------- ---------- ----------E00002 cameras 20000 D00001E00003 TV 15000 D000012 rows selected.

×