Question: I need to get number of record in child table.

Parent table 

```
+-------------+------------+  
| Id          | Name       |  
+-------------+------------+  
| 1           | a          |  
+-------------+------------+    
| 2           | b          |    
+-------------+------------+ 
| 3           | c          | 
+-------------+------------+ 

```

Child table: 

```
+-------------+------------+  
| Id          | Code       |  
+-------------+------------+
| 1           | d1         |  
+-------------+------------+ 
| 1           | d2         | 
+-------------+------------+    
| 1           | d3         |  
+-------------+------------+ 
| 1           | d1         | 
+-------------+------------+    
| 2           | d2         |  
+-------------+------------+ 
| 2           | d3         | 
+-------------+------------+ 
| 3           | d1         |  
+-------------+------------+ 
| 3           | d2         | 
+-------+-----+------------+   

```

Result should like:

```
+-------------+------------+------------+ 
| Id          | Name       | NumOfRec   |  
+-------------+------------+------------+ 
| 1           | a          |        4   |
+-------------+------------+------------+  
| 2           | b          |        2   |
+-------------+------------+------------+  
| 3           | c          |        2   |
+-------------+------------+ -----------+

```

I've tried with COUNT but then I get only number of records for one id but not for other ID's.

Answer: 
use `group by` 

```
select count(*) as NumOfRec  , id from <Child table> group by id;

```

For your updated question, this should work:

```
select parent.id,parent.name,numOdRec from parent join (
    select count(*) as NumOfRec  , id from <Child table> group by id) as childs on childs.id=parent.id

```
Use this code. Writing query with count will give you solutions 

```
select distinct a.id,count(b.id) from parent a, child b where a.id=b.id; 

```