Jump to content

MySQL query stopped working


Yesideez
 Share

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

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

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