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