I have an intermediate table which looks something like this (after I join 2 other tables) :
ID Meta_key Meta_value
22 Company Amazon
22 Address Seattle
25 Company Google
25 Address Mountain View
And so on…
My question is what’s the easiest way to write a single query to get BOTH the company name and address for a given ID? What’s the best way to structure this where clause since I would want something like select meta_value from table where meta_key = “Company” and meta_key = “Address” (that obviously wont work)…I’m sure there is a simple way to do this but can’t seem to think of it right now, I’ll also need aliases to distinguish between the meta_value for company and address in the result set.
Thanks in advance
If you want both keys in same row you could self-join the table
Or if you want single ID even simpler with subquery: