问题描述
您好,
我需要两张桌子: -
1.桌子A
Id |尺寸|
1 | abc
2 | xyz
3 | asd
4 | fgh
5 | opo
2. TableB
Id | TableAId1 | TableAId2 | TableAId3 | TableAId4
1 | 1 | 2 | 3 | 4
2 | 1 | 5 | 3 | 4
结果应显示:
TableBId | Dimension
1 | abc
1 | xyz
1 | asd
1 | fgh
2 | abc
2 | pop
2 | asd
2 | fgh
所以怎么写这个查询在sql server?
请帮帮我。
先谢谢。
Ankit Agarwal
软件工程师
我尝试过:
SELECT ta2.Id,ta1.Dimension
FROM tableA ta1
JOIN tableB ta2 on ta1.id!= ta2.id
WHERE ta1.Id = ta2.TableAId1和ta1.Id = ta2.TableAId2和ta1.Id = ta2.TableAId3和ta1.Id = ta2.TableAId3
Hello,
I need two table:-
1. TableA
Id|Dimension|
1|abc
2|xyz
3|asd
4|fgh
5|opo
2. TableB
Id|TableAId1|TableAId2|TableAId3|TableAId4
1| 1 |2 |3 |4
2| 1 |5 |3 |4
result should be display:
TableBId|Dimension
1|abc
1|xyz
1|asd
1|fgh
2|abc
2|pop
2|asd
2|fgh
so how to write query for this in sql server?
Please help me.
Thanks in Advance.
Ankit Agarwal
Software Engineer
What I have tried:
SELECT ta2.Id,ta1.Dimension FROM tableA ta1 JOIN tableB ta2 on ta1.id != ta2.id WHERE ta1.Id = ta2.TableAId1 and ta1.Id = ta2.TableAId2 and ta1.Id = ta2.TableAId3 and ta1.Id=ta2.TableAId3
这篇关于如何从SQL服务器中的两个表合并中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!