Ferex
Ferex

Reputation: 575

main SELECT gets value from subquery

This query doesn't work but I hope it will suffice to make you understand what I need:

SELECT p.ID, lat.l 
FROM hlp_posts AS p
WHERE p.ID 
IN (SELECT pm.post_id, pm.meta_value AS l FROM hlp_postmeta AS pm WHERE pm.meta_key = "hlp_latitude") lat  

What I need is getting in the main SELECT a value (lat.l) selected in the subquery.
I can get it through a JOIN but I can't use it.

Upvotes: 1

Views: 56

Answers (1)

Darshan Mehta
Darshan Mehta

Reputation: 30849

You can use JOIN instead, e.g.:

SELECT p.id, pm.meta_value
FROM hlp_posts AS p JOIN hlp_postmeta pm ON p.ID = pm.post_id
WHERE pm.meta_key = "hlp_latitude";

Upvotes: 2

Related Questions