我正在尝试通过在查询下面编写内容来获取名为listCode的列,但该列为空。 在此查询中,我尝试将parentid映射到同一表中的listid,并仅在listcode列中获取那些父记录。
SELECT ListCode FROM mytable WHERE ListType = 'CNT' AND ListId =
(SELECT ParentId FROM mytable WHERE ListType = 'CNT')
答案 0 :(得分:0)
您可以使用IN来实现:
SELECT ListCode FROM mytable
WHERE
WHERE ListType = 'CNT'
AND
ListId IN (SELECT Parentid FROM mytable)
或带有EXISTS:
SELECT m.ListCode FROM mytable m
WHERE
WHERE m.ListType = 'CNT'
AND EXISTS (
SELECT 1 FROM mytable
WHERE Parentid = m.ListId
)