In one of my tables i store my advertisement data, thats one row per advertisement. I also store some dates in an other table, but that\'s one row per date because i don\'t
You can use GROUP_CONCAT()
and GROUP BY
to get the results you desire:
SELECT t1.*, GROUP_CONCAT(t2.date) AS dates
FROM Table1 t1
LEFT JOIN Table2 t2
ON t2.ID_adv = t1.ID_adv
GROUP BY t1.ID_adv
This returns all the dates for each advertisement, concatenated by commas. Where there are no dates in Table2 for a particular advertisment, you'll get NULL for the dates column.
To target a particular advertisement, simply add the WHERE
clause:
SELECT t1.*, GROUP_CONCAT(t2.date) AS dates
FROM Table1 t1
LEFT JOIN Table2 t2
ON t2.ID_adv = t1.ID_adv
WHERE t1.ID_adv = 3
GROUP BY t1.ID_adv
You can turn rows into a column with GROUP_CONCAT function