Iam little stucked with this sql query. I have got two tables
TbleName - usrs TbleName - idtb
name | cid cname | cid
------------- ----------------
james | 1100 IT | 1100
john | 1200 HR | 1300
jack | 1100 QA | 1200
bill | 1300 HD | 1400
troy | 1100
SELECT COUNT(*) as 'Total' FROM usrs u WHERE u.cid = 1100;
SELECT c.cname FROM idtb c WHERE c.cid = 1100;
My first query returns 3 and my second query returns IT , Now I want to join this 2 queries into one that would produe me result as this
Total | Cname
------------------
3 | IT
I tried several ways and this worked
SELECT COUNT(*) as 'Total',c.cname FROM usrs u JOIN
idtb c ON u.cid = c.cid WHERE u.cid = 1100
GROUP BY u.cid
But the query does not seem to work when u.cid = 1400, since there are no names in usrs table that have cid value as 1400 and it returns empty result but I want the result to be
Total | Cname
-------------------
0 | HD
The query does not work if there are no records in usrs. I tried using left, right and full joins but did not figure it out. Any help is greatly appreciated.