我有2个表,分别称为“父母”和“孩子”。
父母
parent_id |名称|
孩子
child_id | parent_id | child_name |
我正在寻找一个查询,其输出如下:
parent_id(from parents) | name (unique names from both tables) | is_parent (1,if record is from parent table).
我尝试使用其中一个堆栈中的以下内容:
SELECT
T1.name,T2.child_name
FROM
parents T1
LEFT OUTER JOIN
children T2 ON T1.name = T2.child_name
UNION
SELECT
T1.name,T2.child_name
FROM
parents T1
RIGHT OUTER JOIN
children T2 ON T1.name = T2.child_name
但是它给出了2个单独的列,而不是合并的单个列。
感谢您的帮助。
编辑
添加示例: