Jump to content

[SOLVED] arrrgghh! JOIN problem


SetToLoki

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/74247-solved-arrrgghh-join-problem/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.