开发者

mysql - Can a join query do the same tasks to one query [closed]

开发者 https://www.devze.com 2023-03-30 05:05 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For hel开发者_
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For hel开发者_运维知识库p clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
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
0

精彩评论

暂无评论...
验证码 换一张
取 消