从表中选择column1 = column3的column2?

时间:2022-07-15 04:28:26
KeyTable  Name  Parent
   1       n1    Null
   2       n2    Null
   3       n3     1
   4       n4     2

I want to select col2 from table where col3=col1

我想从表中选择col3 = col1的col2

3 个解决方案

#1


1  

Well from what I see you need join here:

从我看到你需要加入这里:

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

#2


1  

I think this is what you are asking for. But I can't be sure. I suggest you spend longer time preparing your questions:

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

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

#3


0  

I hope i got your Question correctly. this might help you.

我希望我能正确地得到你的问题。这可能对你有帮助。

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

#1


1  

Well from what I see you need join here:

从我看到你需要加入这里:

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

#2


1  

I think this is what you are asking for. But I can't be sure. I suggest you spend longer time preparing your questions:

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

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

#3


0  

I hope i got your Question correctly. this might help you.

我希望我能正确地得到你的问题。这可能对你有帮助。

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