I have two MySQL tables structed as follows;
advert
+-------------------+--------------+
| Field | Type |
+-------------------+--------------+
| id | int(11) |
| title | varchar(150) |
+-------------------+--------------+
advert_interest_record
+--------------+------------+
| Field | Type |
+--------------+------------+
| id | int(11) |
| advert_id | int(11) |
| message | longtext |
+--------------+------------+
I want to select a list of all records from the "advert" table - and get the number of rows from the "advert_interest_record" table where advert.id=response.advert_id.
The SQL I'm using to join the tables is as follows;
SELECT advert.id, advert.title
FROM advert
LEFT JOIN advert_interest_record ON advert.id = advert_interest_record.advert_id
GROUP BY advert_interest_record.advert_id
The first problem I've got is that when there are no records in the "advert_interest_record" table, the record from the "advert" table isn't included in the result - and I need it to be.
My second question is, how would I go about counting the rows in the "advert_interest_record" table?
Any advice on this would be appreciated.
Thanks.