简体   繁体   English

SQL查询联接同一列两次

[英]SQL Query Join Same Column Twice

I have two tables - 我有两个桌子-

Content: 内容:

Id | Name | Source | Target         
---------------------------
1  |  Test  |  en   |    de
2  |  Test1 |  en   |    fr

and Locale : 语言环境

Locale Code | Locale Name
--------------------------
de          |     German
en          |     English
fr          |     French

I need all the records from Content table in the form of - 我需要内容表中的所有记录,形式为-

1 Test  English German

2 Test1 English French

Appreciate your help with the SQL query for this. 感谢您对此SQL查询的帮助。

Give this a try: 试试看:

select c.id, c.name, ls.localename Source, lt.localename Target
from content c
join locale ls on c.source = ls.localecode
join locale lt on c.target = lt.localecode

Result: 结果:

+----+-------+---------+--------+
| ID | NAME  | SOURCE  | TARGET |
+----+-------+---------+--------+
|  1 | Test  | English | German |
|  2 | Test1 | English | French |
+----+-------+---------+--------+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM