I have a MySQL table like:
ID, USER, PARAM, VAL
--------------------
1 | 1 | NAME | ADAM
2 | 1 | AGE | 15
3 | 2 | NAME | EVA
4 | 2 | AGE | 16
5 | 3 | NAME | CRISS
6 | 3 | AGE | 14
And I'm curious if there is a query which would give me something similar to:
1 | ADAM | 15
2 | EVE | 16
3 | CRISS| 14
So far I'm just using the below query and grouping the records in a loop.
SELECT * FROM table WHERE PARAM ='NAME' OR PARAM = 'AGE'
I tried to use GROUP
but without success.
Use join on the same table:
SELECT a.USER user_id, a.VAL user_name, b.VAL user_age
FROM `table` a
INNER JOIN `table` b ON a.USER = b.USER
WHERE a.PARAM = 'NAME'
AND b.PARAM = 'AGE'
Result:
user_id user_name user_age
1 ADAM 15
2 EVA 16
3 CRISS 14
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With