I have 3 tables. I need to join 2 of them and have the join pivot the joined table to return the values in the row. Read below for clarification.
Table 1:
t1ID Title
01 Title 1
01_01 Title 1a
01_02 Title 1b
01_03 Title 1c
02 Title 2
02_01 Title 2a
02_02 Title 2b
... and so on
Table 2 (not used in my join, but shown to see relationship between 3 tables -- contains a fixed number of rows which is 10):
t2ID Description
01 Desc A
02 Desc B
03 Desc C
...
10 Desc J
Table 3:
t1ID t2ID Value
01 01 A
01 02 B
...
01 10 C
01_01 01 D
01_01 02 E
...
02_01 10 F
02_02 01 G
02_02 02 H
...and so on
I want to join Table 1 and Table 3 on t1ID
where Table 1 is the main or master and Table 3 provides detailed values. I need to order Table 3 on t2ID
to keep the sequence so I can handle the output properly.
I would like the query results to look like this:
row[0] row[1] row[2] ... row[10]
Title 1 A B C
Title 1a D E
So I need each row to have the 1st item in the output array as the title and then items 2 through 11 of the output array coming from the join Table 3.
Hope that makes sense.
Thanks for helping me on this.
AMENDED (Getting closer, or at least I no longer have the derived alias error message):
SELECT t1.t1ID, t1.Title, GROUP_CONCAT(t3.Value) AS value
FROM Table1 AS t1
JOIN Table3 AS t3 ON t3.t1ID = t1.t1ID
GROUP BY t3.t1ID
ORDER BY t1.t1ID
All I need to do now is have Table 3 sorted in t2ID ORDER
Can anyone assist with that?