3

I am fighting with a syntax error and I can't really find the problem.

this is my query

 SELECT * FROM wp_postmeta PM1
  WHERE PM1.meta_key = '_pronamic_google_maps_latitude'
  AND PM1.post_id = '$id'
  JOIN wp_postmenta PM2 
  WHERE PM2.post_id = PM1.post_id 
  AND PM2.meta_key = '_pronamic_google_maps_longitude'

and getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'JOIN wp_postmeta PM2' at line 3

could please someone can give me a hint what i'm missing?

2
  • 2
    The error message does not seem to be corresponding with the query you are showing Commented May 24, 2011 at 6:54
  • I think you might have a problem with AND PM1.post_id = '$id' unless $id is the actual value in your table. Have you tried AND PM1.post_id = ". $id? Commented May 24, 2011 at 6:57

2 Answers 2

6

First have to come the join then the rest of the query. So something like

 SELECT * FROM wp_postmeta PM1
  JOIN wp_postmenta PM2 on PM1.post_id = PM2.post_id
  WHERE PM1.meta_key = '_pronamic_google_maps_latitude'
  AND PM1.post_id = '$id'
  AND PM2.meta_key = '_pronamic_google_maps_longitude' 
                                
0
3

You've two where clauses and the join order is wrong:

select ...
from ...
join ... on ...
where ... and ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.