MySQL query with value

I have 2 tables of type 1. After

Id  Title        Date
1   Shaghayegh   2015 
2   Adama        2014 
3   roulett      2013

      

2. PostMeta STRONG>

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 want a result with a mysql query something like this: 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 this?

+3


source to share


2 answers


I found a solution, just use MAX (CASE WHEN ...)



MAX(CASE WHEN (meta.meta_key = 'square') THEN meta.meta_value ELSE NULL END) AS square

      

+3


source


You can use MAX (CASE WHEN...)

to convert value like coloumn



0


source







All Articles