Hi. Help needed to create query
Example:
Table1:Main(M)
Code: |
+--+-----+
|id|title|
+--+-----+
|1 |xxx |
+--+-----+
|2 |yyy |
+--+-----+
|
Table2:Other(O) (O.id_main=M.id)
Code: |
+--+--------------+--------+------+
|id|id_main(=M.id)|id_field|value |
+--+--------------+--------+------+
|1 |1 |1 |hhh |
+--+--------------+--------+------+
|2 |1 |2 |ppp |
+--+--------------+--------+------+
|3 |2 |1 | - |
+--+--------------+--------+------+
|4 |2 |2 |nnn |
+--+--------------+--------+------+
|
The desired result:
Code: |
+----+-------+---------------------+---------------------+
|M.id|M.title|O.value(O.id_field=1)|O.value(O.id_field=2)|
+----+-------+---------------------+---------------------+
|1 |xxx |hhh |ppp |
|2 |yyy | - |nnn |
+----+-------+---------------------+---------------------+
|
O.id_field will be:(1-5)
Code: |
SELECT M.id,title, O.value
FROM xxx_main M INNER JOIN xxx_other O
ON M.id=O.id_main
.............?
|
Help. Thank you.