SQL: consult and compose result

0

Good, I'm trying to make a query for SQLlite, in it I have a table from which I refer to three other tables called Statu_Actual similar to the following table.

tabla: *Statu_Actual*
id_Puesto | id_Clientes | id_Vhiculo | Status
1           1                  1         on
2           5                  4         on
3           null               null      off
4           2                  3         on 
.           .                  .          .

The values of Customer_id, Vehicle_id, Status are the indexes of the other Tables.

I need to make the same tables but with values of each of the tables

tabla: *Statu_Actual*
id_Puesto | id_Clientes     | id_Vhiculo | Status
A110      |   Juan Prez     |   fiat     |    on
A105      |   Pedro zuares  |   Corsa    |    on
A106      |   null          |   null     |    off
A96       |   null          |   null     |    off

In summary this is the query I want to make.

I did this but it repeats some values when placing the last line of code.

from Puestos As P inner join Status_Actual As S ON P.ID_PUESTOS=S.ID_PUESTO
                  Left outer join Clientes as CL ON S.ID_CLIENTE = CL.ID_CLIENTE
        [introducir la descripción del enlace aquí][1]          Left outer join VEH_CLIENTES as VC ON 
                  s.ID_CLIENTE=VC.ID_CLIENTE;

This is the data base

    
asked by J. Ramos 30.10.2017 в 04:25
source

1 answer

0

Adding the clause GROUP BY at the end of your query you can group by fields, for example, the query:

SELECT * FROM Puestos As P 
inner join Status_Actual As S 
ON P.ID_PUESTOS=S.ID_PUESTO
Left outer join Clientes as CL 
ON S.ID_CLIENTE = CL.ID_CLIENTE
Left outer join VEH_CLIENTES as VC 
ON s.ID_CLIENTE=VC.ID_CLIENTE
GROUP BY ID_PUESTOS;

Returns 536 records, compared to 600 obtained without adding this last line, avoiding repetitions in the field ID_PUESTOS .

    
answered by 30.10.2017 / 11:30
source