Jump to content

MySQL query stopped working


Yesideez

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.