How to use inner join?

0

I have this query

$query=$db->query("select empleado,count(*) as v
                   from empleado 
                   inner join oficinas on 
                   empleado.numero=oficinas.numero");

but it gives me this exit

Does someone tell me what I'm doing wrong ?? : 3

The case is the following .. I have a table of employees and another of offices. There are 7 registered offices (in the office table, with different ids of course), and there are 12 employees that belong to one office each. Several of them belong to the same office. But for example, in the office table office 8 is registered but there is no employee in office 8, do you understand me? So since there is no employee in office 8, I do not want to show that record .. I want to show only the employees that belong to an office. Actually I want to show how many employees each office has, but the offices that have employees as well .. But this query did not work for me. : c someone give me a hand please:)

    
asked by Yohanna 04.04.2017 в 16:30
source

2 answers

0

Your error is that the query you did is wrong. You never tried it in the database, did not you?

I'll try to fix it, but without more information it gets complicated:

select oficina,count(empleados) as v 
from 
    empleado 
 inner join 
    oficinas on empleado.numero=oficinas.numero
group by oficina
    
answered by 04.04.2017 в 16:36
0

Using the information from your another question , it seems that the desired query to obtain the number of employees per office, is:

select o.numero, o.ciudad, count(*) as cantidad_empleados
  from oficinas o
  join empleado e
    on e.numero_o = o.numero
 group by o.numero, o.ciudad
    
answered by 05.04.2017 в 03:04