Compare Mysql search results

Asked

Viewed 347 times

0

I need to compare the result of a query not to repeat the result.

For example: I have in the unit register your Cod and speed, but I can have 2 situations:

1) more than one occurrence for the same unit and different speeds, and need to be listed only the occurrence of the higher speed.

cod  - velocidade
100  - 128
100  - 512

as a result of the search I need to list only the most valuable: 100 - 512

2) I can also return more occurrences with the same information, however I need to list only one of them:

cod - velocidade
105 - 512
105 - 512
105 - 512

I need to list only 1x: 105 - 512

How can I be doing these checks?

  • 1

    Felipe, welcome to [en.so], here we do not change the title to solved, just accept the answer that helped us and vote for those we consider good or useful. i edited the title to fit it. Any questions, make a visit to the [tour] or [help]. I also recommend a visit in this post

  • 2

    No need to add [solved] in the question title, here it is done otherwise, mark a V below the answer that you solved the problem or that helped you more, enjoy and see why and how to accept an answer

2 answers

4


2

In question 1 you can do as follows:

SELECT MAX(velocidade) AS velocidade FROM tabela WHERE cod = 100;

In question 2 you can do as follows:

SELECT DISTINCT cod, velocidade FROM tabela WHERE cod = 105 AND velocidade = 512
  • I think he wanted a unique solution to the various test cases.

  • the solution can be separated yes, as there are 2 different queries and a certain DOC. At first I consult only for the unit and after, Clicking on the unit I search for your details, soon I am working with 2 queries. I will apply what was put here and see the result. I will keep you informed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.