3

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 ?

3
  • I'm struggling to understand what you're trying to achieve here. What do the 'App', 'rec' and 'Square' represent? They're not columns in your DB so I'm assuming you want to count records with them? Commented Jul 5, 2015 at 12:35
  • actually i need a result where app is '1' when app was 1 i need all meta_key and meta_value for that post Commented Jul 5, 2015 at 12:41
  • and also i need a row per post Commented Jul 5, 2015 at 12:42

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

You can use MAX (CASE WHEN...) for convert value as a coloumn

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.