mysql - Can a join query do the same tasks to one query [closed]
Table A
Table B
Tabls C1, C2 .... Cn : title field
relationship C INNER JOIN B LEFT JOIN A
query
SELECT C1.title FORM C1
INNER JOIN B on C1.c_id = B.c_id
LEFT JOIN A on B.b_id = A.b_id
Can it be merged into one query ?
I'm not sure I fully understand your question, but if C1
, C2
, ..., Cn
are all "parallel" tables, then perhaps a UNION does the trick:
SELECT C1.title AS title FROM C1 INNER JOIN B on C1.c_id = B.c_id LEFT JOIN A on B.b_id = A.b_id
UNION ALL
SELECT C2.title AS title FROM C2 INNER JOIN B on C2.c_id = B.c_id LEFT JOIN A on B.b_id = A.b_id
UNION ALL
...
UNION ALL
SELECT Cn.title AS title FROM Cn INNER JOIN B on Cn.c_id = B.c_id LEFT JOIN A on B.b_id = A.b_id
精彩评论