Yesideez Posted December 11, 2010 Share Posted December 11, 2010 SELECT i.*,tp.x,tp.y FROM items AS i INNER JOIN users AS u ON u.postcode=sp.outcode INNER JOIN postcodes AS sp ON sp.outcode='EX8' INNER JOIN postcodes AS tp ON tp.outcode=i.outcode WHERE ((tp.x<(sp.x+16093.44) AND tp.x>(sp.x-16093.44)) AND (tp.y<(sp.y+16093.44) AND tp.y>(sp.y-16093.44))) AND i.description LIKE '%apple%' GROUP BY i.id ORDER BY i.added DESC The error I get is "#1054 - Unknown column 'sp.outcode' in 'on clause'" Any idea on how I can get around this please? Link to comment https://forums.phpfreaks.com/topic/221339-mysql-query-stopped-working/ Share on other sites More sharing options...
K_N Posted December 11, 2010 Share Posted December 11, 2010 Well, pardon my amatuer eye, if I'm wrong, but you haven't selected SP yet, when you first make a reference to sp.outcode. Look on the end of your first line: INNER JOIN users AS u ON u.postcode=sp.outcode <- sp.outcode But you don't add sp to your query until the next line: INNER JOIN postcodes AS sp ON sp.outcode='EX8' It looks like you can just switch the order of these two lines and it would work. Link to comment https://forums.phpfreaks.com/topic/221339-mysql-query-stopped-working/#findComment-1145872 Share on other sites More sharing options...
Yesideez Posted December 11, 2010 Author Share Posted December 11, 2010 I think I'm far too tired. I removed the line joining the users table and it works perfectly. Link to comment https://forums.phpfreaks.com/topic/221339-mysql-query-stopped-working/#findComment-1145874 Share on other sites More sharing options...
K_N Posted December 11, 2010 Share Posted December 11, 2010 We all make silly mistakes, I tried to "SORT BY" instead of "ORDER BY" earlier Link to comment https://forums.phpfreaks.com/topic/221339-mysql-query-stopped-working/#findComment-1145876 Share on other sites More sharing options...
Yesideez Posted December 11, 2010 Author Share Posted December 11, 2010 You're right - well spotted I had no need to access that table in this call and no idea why I tried adding it. EDIT: I also removed GROUP BY as it wasn't needed. What is needed is some sleep >< Link to comment https://forums.phpfreaks.com/topic/221339-mysql-query-stopped-working/#findComment-1145877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.