Hi,
im trying to report on 2 tables like the following
tblMain
MainId Name
1 a
2 b
3 c
tblSub
Id MainID Status
1 1 1
2 1 1
3 2 1
3 2 2
basically i want to show all the rows from the main table with a count of the rows in the sub table where that status = 1.
at the moment i have this which would display
SELECT Main.ID, Main.name, COUNT(Sub.ID) AS TheCount
FROM Main LEFT OUTER JOIN
Sub ON Main.USER_ID = Sub.USER_ID
WHERE (Sub.STATUS = 1)
GROUP BY Main.ID, Main.name
MainID Name Count
1 a 2
2 b 1
I need to show the third Main row with a count of zero but because i put in a where clause it wont count the zero records from the sub table.
any ideas?
im trying to report on 2 tables like the following
tblMain
MainId Name
1 a
2 b
3 c
tblSub
Id MainID Status
1 1 1
2 1 1
3 2 1
3 2 2
basically i want to show all the rows from the main table with a count of the rows in the sub table where that status = 1.
at the moment i have this which would display
SELECT Main.ID, Main.name, COUNT(Sub.ID) AS TheCount
FROM Main LEFT OUTER JOIN
Sub ON Main.USER_ID = Sub.USER_ID
WHERE (Sub.STATUS = 1)
GROUP BY Main.ID, Main.name
MainID Name Count
1 a 2
2 b 1
I need to show the third Main row with a count of zero but because i put in a where clause it wont count the zero records from the sub table.
any ideas?