SetToLoki Posted October 21, 2007 Share Posted October 21, 2007 ok its been along time since I attempted to do a JOIN in sql and well it's not like riding a bike I completly forgot. I come up with this SELECT * FROM dyno.customers CROSS JOIN dyno.contracts LEFT JOIN dyno.custcontracts ON (custcontracts.CustID = customers.CustID AND custcontracts.ContractID = contracts.ContractID) CROSS JOIN dyno.properties LEFT JOIN dyno.custproperties ON (custproperties.CustID = customers.CustID AND 'custproperties.PremID' = 'properties.PremID') WHERE customers.CustID = 11111111 I am trying to retrive all data from tables customers, contracts and properties the tables custcontracts and custproperties work as linking tables joining the id for each (eg contractsID) with the ID from the customers table so custproperties contains +---------|--------+ | CustID | PremID | |---------+-------- | |23 |5 | | | | and same for custcontracts So how do I pull all the information from the 3 tables above (allowing for more tables in the future) going off the CustID As my join well plain doesn;t work it fires anf gets me results but they are completly wrong. Quote Link to comment Share on other sites More sharing options...
Simon Moon Posted October 22, 2007 Share Posted October 22, 2007 Should do the trick if i made no typos. SELECT * FROM customers JOIN custcontracts ON custcontracts.CustID = customers.CustID JOIN contracts ON custcontracts.ContractID = contracts.ContractID JOIN custproperties ON custproperties.CustID = customers.CustID JOIN properties ON custproperties.PremID = properties.PremID WHERE customers.CustID = 11111111 Quote Link to comment Share on other sites More sharing options...
SetToLoki Posted October 22, 2007 Author Share Posted October 22, 2007 you sir, are my hero. Topic Solved Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.