Select with inner join

0

Good afternoon, I'm making an app where I need to list all rooms of a user and the last recorded consumption of each room, except that my code searches wrong, if a room has more than one consumption it doubles the same , so I would like some help to sort out my sql command. Here are how-to prints for more than one use per room:

The code I'm using:
SELECT co.id,co.descricao,ca.potencia_atual from comodo co INNER JOIN consumo_atual ca ON ca.Comodo_id = co.id WHERE co.Usuario_id = :id

Print the schema of the two tables:

    
asked by anonymous 30.07.2018 / 19:24

1 answer

0

You can include GROUP BY , which groups the search results.

SELECT co.id,co.descricao,ca.potencia_atual from comodo co 
INNER JOIN consumo_atual ca ON ca.Comodo_id = co.id 
WHERE co.Usuario_id = :id
GROUP BY co.id,co.descricao,ca.potencia_atual
    
30.07.2018 / 20:01