adman4054 Posted May 10, 2016 Share Posted May 10, 2016 Hi, I cant figure out why I keep getting a syntax error. The first "WHERE" works fine, but when I add listing.type it throws an error. Appreciate any help. SELECT * FROM company JOIN listing WHERE company.companyID = listing.companyID AND WHERE listing.type = Supplier LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/301178-mysql-join-syntax-help/ Share on other sites More sharing options...
benanamen Posted May 10, 2016 Share Posted May 10, 2016 (edited) There can only be one "WHERE". This line is wrong: AND WHERE Edited May 10, 2016 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/301178-mysql-join-syntax-help/#findComment-1532964 Share on other sites More sharing options...
mac_gyver Posted May 10, 2016 Share Posted May 10, 2016 the join condition should be part of the JOIN, not as a WHERE clause anyway, which will also eliminate the error - SELECT * FROM company JOIN listing ON company.companyID = listing.companyID WHERE listing.type = Supplier LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/301178-mysql-join-syntax-help/#findComment-1532966 Share on other sites More sharing options...
gizmola Posted May 11, 2016 Share Posted May 11, 2016 I prefer mac_gyver's style, but you can also just fix it per benanamen's comment: SELECT * FROM company, listing WHERE company.companyID = listing.companyID AND listing.type = Supplier LIMIT 0 , 30 Quote Link to comment https://forums.phpfreaks.com/topic/301178-mysql-join-syntax-help/#findComment-1532980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.