If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > how to solve that query in SQL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-06-02, 01:46
lina sam lina sam is offline
Registered User
 
Join Date: Dec 2002
Posts: 3
Question how to solve that query in SQL

I have 6 tables
1)sale tablehas the following col ( saleno,saleqty,itemname,deptname)
2) supply table ( splno,splname)
3) item table( itemname, itemtype, itemcolor)
4) dept table( deptname, deptfloor,deptphone,empno)
5) delivery table ( delno, delqty, itemname,deptname,splno)
6)employee table ( empno, empname, empsalary,deptname bossno)

the query i want to solve is:
list the supplier that delivers all and only brown items?
please if anyone know how, let me know. thanks
Reply With Quote
  #2 (permalink)  
Old 12-06-02, 02:46
bex bex is offline
Registered User
 
Join Date: Nov 2002
Location: South Africa
Posts: 9
Wink Not a lot of info to go on, but here goes

select * from supply where splno in (select splno from delivery where itemname in
(select itemname from item where itemcolor= 'BROWN'))

This will only bring back records for items that have been ordered.

From what i can see regarding your tables - this is the only link.

Enjoy,
Neil
IT Dept
Business Express - JNB
South Africa

1)sale tablehas the following col ( saleno,saleqty,itemname,deptname)
2) supply table ( splno,splname)
3) item table( itemname, itemtype, itemcolor)
4) dept table( deptname, deptfloor,deptphone,empno)
5) delivery table ( delno, delqty, itemname,deptname,splno)
6)employee table ( empno, empname, empsalary,deptname bossno)
Reply With Quote
  #3 (permalink)  
Old 12-06-02, 08:02
gle gle is offline
Registered User
 
Join Date: Dec 2002
Posts: 1
Re: how to solve that query in SQL

It the SQL offered is what is required I would personally do the query as:

SELECT
S.*
FROM
SUPPLY S, DELIVERY D, ITEM I
WHERE
S.SPLNO = D.SPLNO AND
D.ITEMNAME = I.ITEMNAME AND
I.TEMCOLOR = 'BROWN'

This is more efficient, I think. and besides the nested sub-querys are not east to read/maintain - and are just not necessary.
Reply With Quote
  #4 (permalink)  
Old 12-06-02, 08:48
Paul Young Paul Young is offline
Registered User
 
Join Date: Feb 2002
Location: Houston, TX
Posts: 809
If you really want to press the issue the following would be the way to go..

Code:
select S.* 
  from SUPPLY   S
  inner join DELIVERY D on S.SPLNO = D.SPLNO
  inner join ITEM     I on D.ITEMNAME = I.ITEMNAME
 where I.TEMCOLOR = 'BROWN'
__________________
Paul Young
(Knowledge is power! Get some!)
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On