On Saturday, November 17, 2012 9:58:53 PM UTC-7, Avi Chalke wrote:
>
> Dear Friends, I have basic question , please help me. i tried it on 
> mysql 5.0, but not succeed. 
>
> My Question is , I have two tables names employee and dept 
>
> Employee table 
>
>  id(PrimaryKey)        name 
>   1                         Sameer 
>   2                        Sandesh 
>   3                         Pratik 
>   4                          Pranjal 
>   5                         Aniket 
>   6                         Ankur 
> ------------------ 
>
> Dept Table 
>           id is foreign key of reference employee(id) 
>
>  id(FK)                Deptid 
>  1                           1 
>  2                             1 
>  3                         2 
>  4                         1 
>  5                         3 
>  6                         4 
> -------------------- 
>
> Now i want to count that how many id has same dept 
>
> Now i want a sql query to get output like this 
>
>   Deptid        id 
>    1                 3 
>    2                1 
>    3                2 
>    4                2 
>
>
> Please help me.. 
> Thanks in Advance. 
> Avinash Chalke 
>

You don't need a join for that type of query, a simple count(*) and group 
by from the dept table will provide the output you want.  Also, given the 
data you provided the results you want are wrong -- you do have three 
employees in dept 1 but only 1 in each of the other three departments.


David Fitzjarrell

-- 
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to Oracle-PLSQL@googlegroups.com
To unsubscribe from this group, send email to
oracle-plsql-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en

Reply via email to