I am running the below syntax in SQL Server 2000
I want it to show 0 if the count of id is null, and also to show ALL city's in table2 even if they do not exist in table1. I thought a left join was the correct join to use, but it is not showing all city's in table1 nor a 0 if null. Can someone please show me where I made a mistake with the syntax?
Code:
SELECT case when COUNT(ID) IS NULL Then '0' else Count(ID) end AS COUNTOFID, tbl_one.Ename, tbl_one.EPhone, table2.ID AS tbl2ID
FROM tbl_one LEFT JOIN table2 ON tbl_one.city = table2.city
GROUP BY tbl_one.city, table2.ID
ORDER BY table2.ID ASC