Question

I have these two tables:

type

TYPE_ID           TYPE
   1              Type1   
   2              Type2   
   3              Type3   
   4              Type4   

user_type

USRTYPE_ID        TYPE_ID
    1               1
    2               1  
    3               2 
    4               4

What I need to do is count how many types are there in user_type table. For e.g.

SELECT QUERY returns:

 TYPE            QUANTITY
 Type1               2
 Type2               1
 Type4               4
Was it helpful?

Solution

This should work

select count(USRTYPE_ID) as QUANTITY, TYPE
from user_type
inner join type
on user_type.TYPE_ID = type.TYPE_ID
group by TYPE
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top