我想要连接文件图像。 那么,这是我的记录;
tb_barang;
+-----------+-----------+------+
| ID_BARANG | VESSEL | VOY |
+-----------+-----------+------+
| 1 | TMS_GLORY | 0000 |
| 2 | TMS_GLORY | 0000 |
+-----------+-----------+------+
tb_damage_per_coil;
+-----------+-----------+------------+
| ID_DAMAGE | ID_BARANG | KETERANGAN |
+-----------+-----------+------------+
| 35 | 1 | DAMAGE 1 |
| 36 | 2 | DAMAGE 2 |
+-----------+-----------+------------+
2 rows in set (0.00 sec)
tb_file_image
+----------+-----------+----------------------------------------------------------------------------------------------------+
| ID_IMAGE | ID_DAMAGE | FILE_PATH |
+----------+-----------+----------------------------------------------------------------------------------------------------+
| 35 | 35 | D:/XAMPP/htdocs/develop_tsurumaru/assets/iwwi_file/DO_FOLDER/Damage_Report/0510-31-07-2016/35.jpg |
| 36 | 35 | D:/XAMPP/htdocs/develop_tsurumaru/assets/iwwi_file/DO_FOLDER/Damage_Report/0510-31-07-2016/351.jpg |
| 37 | 36 | D:/XAMPP/htdocs/develop_tsurumaru/assets/iwwi_file/DO_FOLDER/Damage_Report/0520-31-07-2016/36.jpg |
| 38 | 36 | D:/XAMPP/htdocs/develop_tsurumaru/assets/iwwi_file/DO_FOLDER/Damage_Report/0520-31-07-2016/361.jpg |
+----------+-----------+----------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
[1]: http://i.stack.imgur.com/FoAKE.jpg
我的目标是,我想将文件的路径连接成一条记录。 我的查询是这样的;
SELECT a.ID_BARANG, b.ID_DAMAGE, a.VESSEL, a.VOY, b.KETERANGAN
FROM tb_barang a
INNER JOIN tb_damage_per_coil b
ON a.ID_BARANG = b.ID_BARANG
WHERE a.VESSEL LIKE "%TMS%" AND a.VOY LIKE "%000%"
+-----------+-----------+-----------+------+------------+
| ID_BARANG | ID_DAMAGE | VESSEL | VOY | KETERANGAN |
+-----------+-----------+-----------+------+------------+
| 1 | 35 | TMS_GLORY | 0000 | DAMAGE 1 |
| 2 | 36 | TMS_GLORY | 0000 | DAMAGE 2 |
+-----------+-----------+-----------+------+------------+
2 rows in set (0.00 sec)
我需要这样
+-----------+-----------+-----------+------+------------+---------------+
| ID_BARANG | ID_DAMAGE | VESSEL | VOY | KETERANGAN | FILE_PATH |
+-----------+-----------+-----------+------+------------+---------------+
| 1 | 35 | TMS_GLORY | 0000 | DAMAGE 1 | FILE1, FILE 2 |
| 2 | 36 | TMS_GLORY | 0000 | DAMAGE 2 | FILE1, FILE 2 |
+-----------+-----------+-----------+------+------------+---------------+
我的查询应该使用什么?
答案 0 :(得分:0)
尝试这样的事情:
select
tb_barang.ID_BARANG,tb_damage_per_coil.ID_DAMAGE,tb_barang.VESSEL,
tb_barang.VOY, tb_damage_per_coil.KETERANGAN,
GROUP_CONCAT('',tb_file_image.FILE_PATH) AS FILE_PATH
from tb_barang
left join tb_damage_per_coil on tb_damage_per_coil.ID_BARANG = tb_barang.ID_BARANG
left join tb_file_image ON tb_file_image.ID_DAMAGE = tb_damage_per_coil.ID_DAMAGE
group by tb_file_image.ID_DAMAGE
fiddle就在这里。