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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joins question

Status
Not open for further replies.

galorin

MIS
Nov 22, 2007
154
GB
I am using the following query to grab records to generate a unique identifier.
Code:
SELECT House_type, softver, builder_id, level, Floor, Revision, dist_id, enq_id
FROM `contacts`.`HouseType` where quote_id = 2203

builder_id, dist_id and enq_id are all numeric fields. I have another table, called Short. It connects the numeric fields to abbreviated company names. It looks like this:
Code:
-------------------
|Comp_ID|ShortCode|
|-------|---------|
|  1    |  aaa    |
|  2    |  acb    |
|  3    |  afw    |
-------------------
A third table contains company names to a numeric company ID, so HouseType.builder_id = Short.CompID = company.CompID

How do I change the query so that it will return the ShortCode for builder_id, dist_id and enq_id instead of just one?
 
Code:
SELECT h.House_type
     , h.softver
     , b.ShortCode AS builder_ShortCode
     , h.level
     , h.Floor
     , h.Revision
     , d.ShortCode AS dist_ShortCode
     , e.ShortCode AS enq_ShortCode
  FROM `contacts`.`HouseType` AS h
INNER
  JOIN Short as b
    ON b.Comp_ID = h.builder_id
INNER
  JOIN Short as d
    ON d.Comp_ID = h.dist_id
INNER
  JOIN Short as e
    ON e.Comp_ID = h.enq_id
 WHERE h.quote_id = 2203

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top