Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling Records from Three Tables 1

Status
Not open for further replies.

byrne1

Programmer
Aug 7, 2001
415
US
I need help in creating a SQL statement that will pull records from three tables. The three tables that I have are as follows:

ITEMS
- Itemnbr
- DepartmentNum
- VendorNum

ITMDESCR
- Itemnbr
- Description1

VENDOR
- VendorNum
- Name

I need a query that will pull itemdesc.description1, item.vendornum and vendor.name for all items in the item table whose departmentnum=61. I need the resulting set grouped by itemdesc.description1.

Everything I've tried so far has failed. I either don't get what I need or I get a SQL query that times out.

TIA!!!
 
How's this:

Code:
SELECT ID.description1, I.vendornum, V.name FROM ITEMS I INNER JOIN ITEMDESC ID ON I.Itemnbr = ID.Itemnbr INNER JOIN VENDOR V ON I.VendorNum = V.VendorNum WHERE DepartmentNum = 61

I must point out however, that in most cases when you see a field named 'Description1', it is a red flag that the tables are not normalized. You may want to review 'The Fundamentals of Relational Database Design'


Leslie
 
Code:
select ITMDESCR.description1
     , ITEMS.vendornum 
     , VENDOR.name 
  from items
inner
  join ITMDESCR  
    on ITEMS.Itemnbr
     = ITMDESCR.Itemnbr
inner
  join VENDOR  
    on ITEMS.VENDORNum
     = VENDOR.VENDORNum     
 where ITEMS.departmentnum = 61  
order
    by ITMDESCR.description1

if you prefer html to word docs (i know i do, which is why i got permission from paul litwin to mirror it), you can also read the same article on the web here -- Fundamentals of Relational Database Design

rudy
SQL Consulting
 
Ba-da-bing!

That did the trick. Thank you very much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top