|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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!!! |
|
#2
|
|||
|
|||
|
select WID, Street_No, City, State
from WAREHOUSE where wid is in (select wid from DIVISION where name = 'computers' or name = 'electronics') |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
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') |
|
#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') |
|
#6
|
|||
|
|||
|
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') |
|
#7
|
|||
|
|||
|
YOU ARE MY HERO.
thank you! |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Select multple records |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|