2012-04-10 78 views
0

我有這種情況:合併和兩個表的字符串替換表ID SQL

Table A: 
+----+------------+ 
| id | text  | 
+----+------------+ 
| 33 | str1  | 
| 34 | str2  | 
| 35 | str3  | 
| 36 | str4  | 
+----+------------+ 

Table B: 
+----+--------+------+------------+----------+-------+ 
| id | title | teme | year  | ed  | cont | 
+----+--------+------+------------+----------+-------+ 
| 8 |  33 | 34 | 2012-04-06 |  35 | 36 | 
+----+--------+------+------------+----------+-------+ 

可能有一個查詢有這樣的結果:從JOIN

+----+--------+------+------------+----------+-------+ 
| id | title | teme | year  | ed  | cont | 
+----+--------+------+------------+----------+-------+ 
| 8 | str1 | str2 | 2012-04-06 |  str3 | str4 | 
+----+--------+------+------------+----------+-------+ 

桌上的結果在另外兩張桌子之間。

我所用的DBMS是Mysql的

在此先感謝

回答

3

我能想出的唯一事情是

select b.id, 
     (select a.text from tableA a where a.id = b.title) as title, 
     (select a.text from tableA a where a.id = b.teme) as teme, 
     year, 
     (select a.text from tableA a where a.id = b.ed) as ed, 
     (select a.text from tableA a where a.id = b.cont) as cont 
from tableB b 
where b.id = 8