Jump to content

**SOLVED** MULTIPLE ON-WHERE WITH A SINGLE JOIN IS ALLOWED ?


swatisonee

Recommended Posts

Hi,

I'm finding my way thru JOINS and have this single statement to execute. It doesnt work because its syntactically wrong. I'm not able to figure out how I should change it and would appreciate some guidance. Thanks.

[code]$sql = "SELECT `Enq`.* FROM `Enq` LEFT JOIN `Budget`

ON `Enq`.Enquiryid=`Budget`.Enquiryid WHERE `Budget`.Enquiryid IS NULL

AND ON  `Enq`.Visitid =`Budget`.Visitid WHERE `Budget`.Visitid IS NULL

// syntactically wrong


AND ( (`Enq`.`Visitid`= '0' || `Enq`.`Visitid` IS NULL)

AND  `Enq`.Category!= 'D' AND `Enq`.Category!= 'A' )

and so on and so forth.... [/code]


Basically, if the field Visitid has a value in Enq but does not appear in a record in Budget, it should get selected.
Also, all other records in Enq where Visitid is 0 or null should also get selected.
This is because, there are records in Budget with value in the Visitid field that correspond to a value in Enq and those should not be selected.
Link to comment
Share on other sites

Hi, thanks for replying but that was the first option i had tried but it didnt return any records.

I hope i can explain correctly :

a. I have 2 table that need to be joined.

b. I have 3 types of data to select from between these 2 tables.
* all records from Enq which do not find a match in Budget
* all records from Enq where the field visitid has null value which do not find a match in Budget
* all records from Enq where the field visitid has a value but which do not find a match in Budget
* all record in Enq which have values in both enquiryid and visitid but does not find a match in Budget

Records have to be scanned to check that both the enquiryid and visitid fields of Budget return null values. My problem is the second and third have records which can be subsets of the first.

The field visitid comes from a third table called Visit.

Any suggestions pl? Thanks.
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.