Hi All,
I have a requirement where the table design is like below
Table PC
colA_PK | colB |
1 | aa |
2 | bb |
3 | cc |
4 | dd |
Table PSC
colC_PK | colA_FK | ColD |
1 | 1 | qwe |
2 | 1 | rty |
3 | 1 | uio |
4 | 1 | asd |
5 | 1 | fgh |
6 | 2 | vcd |
7 | 3 | asd |
8 | 4 | sas |
Table PT
colA_FK | colC_FK | ColE |
1 | 1 | abc |
1 | 2 | def |
1 | 3 | ghi |
2 | 4 | jkl |
2 | 4 | mno |
2 | 5 | pqr |
3 | 6 | stu |
3 | 6 | vwx |
I have used below query to return all records from Table PSC
select psc.colC_PK as ID, Count(pt.colC_FK) as IDCount from psc left join pt on psc.colC_PK= pt.colC_FK where pt.colA_FK = 1 group by psc.colC_PK
I am expecting the output in the following manner
ID | IDCount |
5 | 2 |
6 | 1 |
7 | 0 |
8 | 0 |
But I am getting only
ID | IDCount |
5 | 2 |
6 | 1 |
Any help is appreciated
Thanks,
Saleem