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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.