SQL duplicate management

2

It turns out that I have to make a query in which I get returned several duplicate records, except for a field that is counters.

The question in itself is that I need to collect the record with the highest value of counters. Right now the sentence is as follows

SELECT * FROM Bares B inner JOIN Contadores C on B.idProd = C.idLocal where B.EmpresaOperadora='B'

What returns me

Of those 3 records, I should draw first since it is not repeated and the last one since it is the one with the highest value of countersEntradas. I understand that it must be an easy thing, but I am not very focused on this topic and what I have tried has not been a good result. Greetings

    
asked by Nuxk 07.05.2018 в 12:47
source

1 answer

2

I think the key is in the MAX function, it's an aggregate function and for example combined with GROUP BY I think I can help you with this query.

Link

On the other hand, for you to have an example that can help you, I would touch up your query in this way:

SELECT idProd, nombreBar, Maquina, MAX(contadoresEntradasAnteriores) FROM Bares B inner JOIN Contadores C on B.idProd = C.idLocal where B.EmpresaOperadora='B
GROUP BY idProd, nombreBAR, Maquina

I hope you can use at least guidance

    
answered by 07.05.2018 в 13:04