Reputation: 381
i have 2 table like 1.post
Id Title Date
1 Shaghayegh 2015
2 Adama 2014
3 roulett 2013
2.postmeta
id Post_id Meta_key Meta_value
1 1 app 1
2 1 rec url-rec1
3 1 Square url-sq1
4 2 app 0
5 2 rec NULL
6 2 Square NuLL
7 3 app 1
8 3 rec url-rec2
9 3 Square url-sq2
I need a result with mysql query something like this on where app=1
Post.id Post.Title App rec Square
1 Shaghayegh 1 url-rec1 url-sq1
3 roulett 1 url-rec2 url-sq2
Is there a way to do that ?
Upvotes: 3
Views: 54
Reputation: 381
i found the solution, just use MAX (CASE WHEN...)
MAX(CASE WHEN (meta.meta_key = 'square') THEN meta.meta_value ELSE NULL END) AS square
Upvotes: 3