poleposters Posted April 11, 2008 Share Posted April 11, 2008 Hi I have three tables. One has the user information, one their address and the other some listing information. I want to join them. I tried doing something similar to joining 2 tables but thats not working. Can anyone tell me what I'm doing wrong? $selectlinks="SELECT * from coupon,users,address WHERE coupon.business_id=users.business_id=address.business_id AND postcode like '%$searchterm' and cat_id=$catid or coupon.business_id=users.business_id=address.business_id AND suburb like '%$searchterm' and cat_id=$catid order by paid_listing DESC limit $start,$numentries"; Link to comment https://forums.phpfreaks.com/topic/100632-solved-correct-syntax-to-join-3-tables/ Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 use left join ... select table1.fieldname,table2.fieldname,table3.fieldname.... from table leftjoin table2 on table1.fieldname=table2,fieldname leftjoin table3 on table2.fieldname=table3.fieldname where any condition... Link to comment https://forums.phpfreaks.com/topic/100632-solved-correct-syntax-to-join-3-tables/#findComment-514657 Share on other sites More sharing options...
poleposters Posted April 11, 2008 Author Share Posted April 11, 2008 Great! Except now I'm running into some trouble with a similar query. $selectlinks="SELECT * FROM coupon LEFT JOIN users ON coupon.business_id=users.business_id LEFT JOIN address ON users.business_id=address.business_id WHERE business_id=$businessid order by date_added DESC limit $start,$numentries"; I get this message Column 'business_id' in where clause is ambiguous Link to comment https://forums.phpfreaks.com/topic/100632-solved-correct-syntax-to-join-3-tables/#findComment-514689 Share on other sites More sharing options...
zenag Posted April 11, 2008 Share Posted April 11, 2008 where should be specified as WHERE tablename.business_id=$businessid Link to comment https://forums.phpfreaks.com/topic/100632-solved-correct-syntax-to-join-3-tables/#findComment-514700 Share on other sites More sharing options...
poleposters Posted April 11, 2008 Author Share Posted April 11, 2008 Brilliant! Thanks so much Link to comment https://forums.phpfreaks.com/topic/100632-solved-correct-syntax-to-join-3-tables/#findComment-514747 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.