I'm trying to group rows equal, but based on a value.
I know it is possible through sub-query
, however as I am using inner join
I could not apply.
SELECT * FROM Concessionarias C inner join Concessionarias_Marcas CM on
C.id = CM.Concessionarias_id and C.Estados_id = 14 group by C.id order by
(Marcas_id = 31) DESC;
This Query returns the following information:
DBstructure: Problem:
When I put it to group, it groups correctly, but I wanted to group it when I grouped the item that it is with (Marks_id = 31).
Since I have 2 repeated lines, when grouping, it would choose the line where Marks_id is equal to 31. In this case, he is choosing (Marks_id = 12)
How can I group multiple equal items, preferably one field (in the case of Marks_id)?