我有两张桌子:
表格1:
---------------------------
|id_column1 | name_column |
---------------------------
| 1 | my_name1 |
| 2 | my_name2 |
---------------------------
表2:
--------------------------------------
|id_column2 | surname_column | fk_id1|
--------------------------------------
| 111 | my_surname1 | 1 |
| 222 | my_surname2 | 2 |
--------------------------------------
fk_id1 is foreign key referenced to table1.id_column1
SELECT * FROM table1 WHERE fk_id1=1;
--------------------------------------
|id_column2 | surname_column | fk_id1|
--------------------------------------
| 111 | my_surname1 | 1 |
我怎样才能得到这个(是否有可能加入两个表列作为结果):
------------------------------------------------
|id_column2 | surname_column | fk_id1| name |
------------------------------------------------
| 111 | my_surname1 | 1 |my_name1 |
如下所示:
SELECT * FROM table2 WHERE fk_id1=1 AND SELECT name FROM table1 WHERE id_column1=1;