There are 2 tables and I have to join both the tables.
Table A has few columns but both tables have “city_code” column.
Table A has unique records if we talk about “city_code”. Only 1 “city_code” can be entered.
But Table B doesn’t have unique record if we talk about “city_code”.
There might be more than 1 record which has same “city_code”. I have to apply group by on table A behalf of Table A column name “status” and have to apply a filter on column “user_name” which is available in Table B.
I am doing like this:
Select a.status as status, count(a.city_code) as count from A a
Left Join B b on a.city_code = b.city_code
where b.user_name = "xyz" group by a.status```
Now problem is, Table A has only 18 records(All are unique city_code-wise) and Table B has something 100 records(each city_code has more than 4 records) when I run this query I get the result like this:
status count
INPROGRESS 89
COMPLETED 12
While I want
only records which are available into table A but filter user_name which is in Table B.
Faheem Ilahi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.