1 (edited by chrizz 2004-11-24 21:47)

Topic: Another mysql-question

Hi!

I have this query:

SELECT a.*, i.filename AS first_image FROM ads AS a INNER JOIN ads_images AS i ON i.adid = a.adid WHERE ... GROUP BY adid ORDER BY a.timestamp DESC, i.filename ASC LIMIT 10;

As you can se there are two tables. An ad could have one image (or more than one) or no image at all. The ads_images contains only images, and no null-value-rows for the ads who dont have images (rows with the adid and null for the rest of the columns that is).

The query above results only rows containing ads with images, the ones without are not selected since there is no adid in ads_images for that ad. Is there another solution to this than to insert "null-rows" to the ads_images but only containing the adid?

Re: Another mysql-question

Yes, a LEFT JOIN instead of an INNER JOIN.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: Another mysql-question

thanks / tack smile