I’ve made a query that works as needed when there is at least 1 row in the url_status table where u.urlid = us.urls however it won’t work if this isn’t true. What could I do to overcome this?
SELECT u.*, COUNT(*) AS historySize
FROM host_urls u, url_status us
WHERE u.publicationid = 1
AND us.urlid = u.urlid
GROUP BY u.urlid
You could use an outer join, specifically a left join, which will return at least one result row for each row in
host_urls, even if it has no corresponding rows inurl_status.You can replace the
COUNT(*)withCOUNT(us.urlid)(or another column fromurl_status) if it’s important thathistorySizebe zero when there were no matching rows inurl_status.