Autor | Zpráva | ||
---|---|---|---|
piiiiiiiip Profil |
Dobrý den, snažím se spojit dvě tabulky:
tabulka 1 ID COL1 COL2 1 aaa aaa 2 bbb bbb tabulka 2 ID TABONE_ID COL1 1 1 ccc 2 1 ddd 3 1 eee 4 2 fff Chci přiřadit vše z druhé tabulky k první podle id ale vůbec se mi to nedaří. Zkoušel jsem jak right tak i left join. Nepomohlo ano group by. return $this->database->query(" SELECT images.reported, images.img_id, report.reported_by, report.imgs_id FROM images LEFT JOIN report ON report.imgs_id = images.img_id WHERE images.reported = 6 GROUP BY images.img_id ")->fetchall(); Mělo by to vrátit ID 1 - ccc,ddd,eee ID 2 - fff Vrací to ID 1 - ccc ID 2 - fff |
||
Kajman Profil |
#2 · Zasláno: 12. 4. 2017, 15:59:46
Pokud stačí jeden sloupec oddělený čárkami, tak zkuste
SELECT images.reported, images.img_id, Group_concat(report.reported_by) seznam FROM images LEFT JOIN report ON report.imgs_id = images.img_id WHERE images.reported = 6 GROUP BY images.reported, images.img_id Pokud už tam bude více dat, tak si pro inspiraci pročtěte porovnání různých řešení Moved Permanently |
||
Časová prodleva: 6 let
|
0