Reputation: 95
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?
Upvotes: 3
Views: 115
Reputation: 2189
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'
Upvotes: 6
Reputation: 78581
You've two where clauses and the join order is wrong:
select ...
from ...
join ... on ...
where ... and ...
Upvotes: 3