0
我在MySQL數據庫中有兩個表A和表B,我想要它們兩個的列輸出,
表A列a_id整數(5),a_name VARCHAR(20)。
表B列b_id整數(5),b_name varchar(20),a_id varchar(10)。SQL Query從下面兩個表中檢索數據的情況
And tables records are,
select * from a;
+------+--------+
| a_id | a_name |
+------+--------+
| 1 | a1 |
| 2 | a2 |
+------+--------+
select * from b;
+------+--------+------+
| b_id | b_name | a_id |
+------+--------+------+
| 1 | b1 | 1,2 |
| 2 | b2 | 1 |
| 3 | b3 | null |
+------+--------+------+
Now i want to get data which are in b table but also
with a_name column,
+------+--------+-------+
| b_id | b_name | a_name|
+------+--------+-------+
| 1 | b1 | a1,a2 |
| 2 | b2 | a1 |
| 3 | b3 | null |
+------+--------+-------+
如何實現這個輸出我有加入試過,但沒有得到應有的result.is有哪些可以結合A1,A2值和row.any幫助返回任何聚合函數是非常讚賞謝謝。
您需要正常化第二個表,如果你不能與現有的架構做,然後結帳'用find_in_set' –
是LEFT JOIN加盟將給3條記錄與空值,但該值A1,A2爲第一排如何得到這個? – HUM