mounika Posted November 7, 2006 Share Posted November 7, 2006 HI,Can any one tell what should be the query to count from two tables where we have to get zero count for null.Ex:[b]Table 1: Table 2:[/b][b]ID Name ID Subjects Table1ID [/b] 1 abc 1 English 1 2 xyz 2 Maths 13 mno 3 Science 1Result should be:[b]Name count(subjects)[/b]abc 3xyz 0mno 0Thanks in Advance! Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 Try the following (UNTESTED):[code]SELECT t1.name, COUNT(t2.id)FROM t1 LEFT JOIN t2 ON ( t2.table1id = t1.id )GROUP BY t1.id[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.