从表中选择column1 = column3的column2?

时间:2015-05-22 12:51:23

标签: sql sql-server

KeyTable  Name  Parent
   1       n1    Null
   2       n2    Null
   3       n3     1
   4       n4     2

我想要select col2 from table where col3=col1

3 个答案:

答案 0 :(得分:1)

从我看到你需要join这里:

select
    t1.col1,
    t1.col2,
    t1.col3,
    t2.col2
from table as t1
    left outer join table as t2 on t2.col3 = col1

答案 1 :(得分:1)

我认为这就是你要求的。但我不能确定。我建议你花更长的时间准备你的问题:

SELECT t1.name, t2.name
FROM yourtable t1
JOIN yourtable t2
ON t1.parentid = t2.KeyTable

答案 2 :(得分:0)

我希望我的问题正确无误。这可能对你有帮助。

select Name 
from Table
where isnull(KeyTable,0) = isnull(Parent,0)