[thelist] table join for 4 tables
Brian Cummiskey
Brian at hondaswap.com
Thu Nov 3 12:04:02 CST 2005
Unsupported Browser wrote:
> I'm pretty decent with single tables and even double tables, but I have one
> query that has to join 4 tables and I am lost. here is the basic gist.
> I need to look up information where table1 has a status of 10 and then I
> need to get the personid from table1 and pull in the personal information
> from table2, using the shippingid from table1 I need to get the address
> (about 6 fields) associated with that from table3, then I need to get the
> sku information from table4 using the skuid from table1.
this should work in mysql and mssql:
select YOURFIELDS.table1, YOURFIELDS.table2, YOURFIELDS.table3,
YOURFIELDS.table4 from table1
left outer join table2 on table1.personid = table2.personid
left outer join table3 on table1.shippingid = table3.shippingid
left outer join table 4 on table1.skuid = table4.skuid
where table1.status = '10'
Assuiming no nulls in table1, you should pull what you need. Plug in
the right YOURFIELDS elements for each table that you awnt to pull.
More information about the thelist
mailing list