MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old November 14th, 2003, 12:20 PM
JEH JEH is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 JEH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Select multple records

PLEASE HELP!
I have 2 tables, DIVISION(DID, Name, Mgr_EID, WID) and WAREHOUSE(WID, Street_No, City, State, ZIP).

I need to select WID, Street_No, City and State for all warehouses that have both "Computers" and "Electronics" divisions. (Computers and Electronics are in Name column in DIVISION table.

I think I need to use an EXISTS statement, but I'm not sure - any help would be very much appreciated! THANK YOU!!!

Reply With Quote
  #2  
Old November 14th, 2003, 12:28 PM
smackmeister smackmeister is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 21 smackmeister User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
select WID, Street_No, City, State
from WAREHOUSE
where wid is in (select wid from DIVISION where name = 'computers' or name = 'electronics')

Reply With Quote
  #3  
Old November 14th, 2003, 12:52 PM
JEH JEH is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 JEH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks, but that's not quite what I'm looking for - that selects any warehouse that has and Electronics OR Computers division, I need one that selects any warehouse that has BOTH Computers AND Electronics division.

I tried switching the OR in your query to AND, but that doesn't work - doesn't return any results.

Any other suggestions/ideas? Divisions table is below so you can see what I'm working with...

THANK YOU!!

Division Table:
DID Name Mgr_EID WID
10 Apparel 1 1
11 Toys 6 1
12 Sports goods 11 1
13 Computers 16 1
14 Utility 18 1
21 Apparel 20 2
22 Toys 24 2
23 Sports goods 28 2
24 Computers 32 2
31 Apparel 40 3
32 Toys 44 3
33 Sports goods 48 3
34 Computers 52 3
35 Electronics 58 3
41 Apparel 60 4
42 Toys 64 4
43 Sports Goods 68 4
44 Computers 72 4
45 Electronics 76 4
46 Hardware 83 4

Reply With Quote
  #4  
Old November 14th, 2003, 01:05 PM
smackmeister smackmeister is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 21 smackmeister User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
okay, try:

select WID, Street_No, City, State
from WAREHOUSE
where wid is in (select wid from DIVISION where name = 'electronics')
and wid is in (select wid from DIVISION where name = 'computers')

Reply With Quote
  #5  
Old November 14th, 2003, 01:06 PM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 5
Then why not use this:

SELECT WID, Street_No, City, State
FROM WAREHOUSE
WHERE wid IN (
SELECT wid FROM DIVISION WHERE name = 'computers')
AND wid IN (
or name = 'electronics')

Reply With Quote
  #6  
Old November 14th, 2003, 01:06 PM
jstrohofer jstrohofer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Cincinnati, OH USA
Posts: 111 jstrohofer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 3 sec
Reputation Power: 5
Crap....sorry for the incomplete double-postings.. user error
I was trying to type this, I think:


SELECT WID, Street_No, City, State
FROM WAREHOUSE
WHERE wid IN (
SELECT wid FROM DIVISION WHERE name = 'computers')
AND wid IN (
SELECT wid FROM DIVISION WHERE name = 'electronics')

Reply With Quote
  #7  
Old November 14th, 2003, 01:07 PM
JEH JEH is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 3 JEH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
YOU ARE MY HERO.

thank you!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Select multple records


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway