Ok, I have a problem with joining 2 tables (with INNER JOIN). First table containts categories list (ecc. for photo albums, or blog posts) while the second table contains \"the
To retain the rows from galeries
with no matching ID in photos, you will need to join photos on galeries with LEFT JOIN
instead of INNER JOIN
:
SELECT galeries_id, galeries_title,
photos.photos_id, photos.photos_gal_id, photos.photos_link
FROM galeries
LEFT JOIN photos
ON galeries.galeries_id=photos.photos_gal_id
GROUP BY photos_gal_id
This will give you:
galeries_id galeries_title photos_id photos_link
1 blabla 3 test.jpg
2 bla bla2 NULL NULL
3 etata 5 test.jpg
And if you wish to replace NULL with an empty string, you can use:
SELECT
IFNULL(photos.photos_id, ''),
IFNULL(photos.photos_link, '')