I have 2 table 1st Table is
我有2桌第1桌是
Customer Number, Customer Name, Place, State
- 1, ABC, DEL, DL
- 2, ABD, PNP, HR
- 3, ABE, LDH, PB
1,ABC,DEL,DL
2,ABD,PNP,HR
3,ABE,LDH,PB
Another Table
Code, Description
- DEL, Delhi
- DL , Delhi
- PNP , Panipat
- HR , Haryana
- LDH , Ludhiana
- PB , Pubjab
DL,德里
PNP,Panipat
人力资源,哈里亚纳邦
LDH,卢迪亚纳
PB,Pubjab
I need a SQL Query which shows the following Result
我需要一个SQL查询,它显示以下结果
Customer Number, Customer Name, Place, State
- 1, ABC, DELHI, DELHI
- 2, ABD, PANIPAT, HARYANA
- 3, ABE, LUDHIANA, PUNJAB
1,ABC,DELHI,DELHI
2,ABD,PANIPAT,HARYANA
3,ABE,LUDHIANA,PUNJAB
1 个解决方案
#1
2
Basically, you need to join Table2
twice on Table1
because are two dependent columns on it.
基本上,您需要在Table1上连接Table2两次,因为它上面有两个依赖列。
SELECT a.CustomerNumber,
a.CustomerName,
b.Description Place,
c.Description State
FROM Table1 a
INNER JOIN Table2 b
ON a.Place = b.Code
INNER JOIN Table2 c
ON a.State = c.Code
To further gain more knowledge about joins, kindly visit the link below:
要进一步了解联接,请访问以下链接:
- Visual Representation of SQL Joins
SQL连接的可视化表示
OUTPUT
╔════════════════╦══════════════╦══════════╦═════════╗
║ CUSTOMERNUMBER ║ CUSTOMERNAME ║ PLACE ║ STATE ║
╠════════════════╬══════════════╬══════════╬═════════╣
║ 1 ║ ABC ║ Delhi ║ Delhi ║
║ 2 ║ ABD ║ Panipat ║ Haryana ║
║ 3 ║ ABE ║ Ludhiana ║ Pubjab ║
╚════════════════╩══════════════╩══════════╩═════════╝
#1
2
Basically, you need to join Table2
twice on Table1
because are two dependent columns on it.
基本上,您需要在Table1上连接Table2两次,因为它上面有两个依赖列。
SELECT a.CustomerNumber,
a.CustomerName,
b.Description Place,
c.Description State
FROM Table1 a
INNER JOIN Table2 b
ON a.Place = b.Code
INNER JOIN Table2 c
ON a.State = c.Code
To further gain more knowledge about joins, kindly visit the link below:
要进一步了解联接,请访问以下链接:
- Visual Representation of SQL Joins
SQL连接的可视化表示
OUTPUT
╔════════════════╦══════════════╦══════════╦═════════╗
║ CUSTOMERNUMBER ║ CUSTOMERNAME ║ PLACE ║ STATE ║
╠════════════════╬══════════════╬══════════╬═════════╣
║ 1 ║ ABC ║ Delhi ║ Delhi ║
║ 2 ║ ABD ║ Panipat ║ Haryana ║
║ 3 ║ ABE ║ Ludhiana ║ Pubjab ║
╚════════════════╩══════════════╩══════════╩═════════╝