V-K
V-K

Reputation: 25

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.

Upvotes: 2

Views: 4410

Answers (1)

Mosty Mostacho
Mosty Mostacho

Reputation: 43434

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 |
+----+-------+---------+--------+

Upvotes: 5

Related Questions