[英]How can I join a table to return all rows right and in addition a null row?
I have two tables, one with a list of parts, and another with a list of attributes. 我有两个表,一个带有零件列表,另一个带有属性列表。 What I'm trying to achieve is to list all parts with their attributes, and also the base row itself a la:
我想要实现的是列出所有具有其属性的部分,以及基本行本身的la:
Part Attribute
----------------
Cake Batman
Cake Princess
Cake Spiderman
Cake NULL
QUERY
----------------
SELECT p.Name, pa.Name
FROM PartsTbl p
LEFT JOIN PartAttrib pa ON p.Name= pa.BaseName
WHERE p.Name = 'Cake'
Currently, this only returns everything except the last row. 当前,这仅返回除最后一行以外的所有内容。 How can I produce the last row as part of the same query, instead of by running a second query?
如何在同一查询中生成最后一行,而不是通过运行第二个查询?
UPDATE --------------- 更新---------------
Table Structure
PartsTbl - Name
PartAttrib - BaseName (To PartsTbl.Name), Name
A simple Union is your friend :o) 一个简单的联盟是你的朋友:o)
SELECT p.Name, pa.Name
FROM PartsTbl p
LEFT JOIN PartAttrib pa ON p.Name= pa.BaseName
WHERE p.Name = 'Cake'
UNION
SELECT Name, NULL
FROM PartsTbl
WHERE Name = 'Cake'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.