In the scenario I have to get the data in the right order based on the precedence structure of the rows. Let the table data be:
Table (Desc - A part of B)
col1 col2 col3
a 1 11
a 1 12
a 1 13
b 2 21
b 2 22
b 2 23
Table (Desc - Sequence)
col1 col2 col3
aa 11 12
bb 13 14
cc 12 13
pp 21 22
qq 23 24
rr 22 23
The result I am expecting:
col1 col2
a aa
a cc
a bb
b pp
b rr
b qq
I'm using MySQL.
CodePudding user response:
You can try to use JOIN
with ORDER BY T1.col
then T2.col2
SELECT T1.col1,
T2.col1
FROM T1
INNER JOIN T2
ON T1.col3 = T2.col2
ORDER BY T1.col1,
T2.col2