我想用(ID_1)ID的數組從TABLE_1選擇從TABLE_2得到所有行ID_2 = ID_1MySQL的子查詢結果陣列
SELECT field_b
FROM table_2
WHERE id_2 IN (
SELECT id_1 FROM table_1 WHERE field_a = 1234
);
以下是參考比如我的表:
mysql> select * from table_1;
+-------+---------+
| id_1 | field_a |
+-------+---------+
| 1 | 1234 |
+-------+---------+
| 2 | 1234 |
+-------+---------+
mysql> select * from table_2;
+---------+---------+
| id_2 | field_b |
+---------+---------+
| 1 | 5678 |
+-------+-----------+
| 2 | 0013 |
+-------+-----------+
你想進行簡單的INNER JOIN? SELECT * from table_2 INNER JOIN table_1 on table_1.id_1 = table_2.id_2?你可以添加任何你想要的條件,例如WHERE field_a = 1234 – mkk
你使用'IN'發佈的代碼應該可以工作... –
@Martin現在你提到它是個好主意。我想知道OP實際上有什麼麻煩? – jadarnel27