Prioritize row in sql queries

1

In a Results with 2 fields exactly alike, how to do that only show lines that the priority column is marked as 1

id   |   origem   | destino  | daia_inicio  | data_fim   |  valor  | prioridade
01   |   Galeão   |  Barra   | 01/01/2018   | 31/12/2018 |  400,00 | 0
02   |   Galeão   |  Barra   | 10/01/2018   | 20/02/2018 | 1000,00 | 1
03   |   Rio      |  Barra   | 10/01/2018   | 20/02/2018 | 2000,00 | 0
04   |   São paulo|  Barra   | 10/01/2018   | 20/02/2018 | 4000,00 | 0
05   |   Brasilia |  Barra   | 10/01/2018   | 20/02/2018 | 8000,00 | 0

Expected result : (Only show line 2 because it has priority checked)

  

02 Galeão Barra 10/02/2018 - 20/02/2018 1000,00

    
asked by anonymous 12.02.2018 / 16:10

2 answers

3

You will have to use the WHERE clause in your query to filter the results.

Example:

SELECT * FROM nome_da_tabela WHERE prioridade = 1

See the SELECT documentation

    
12.02.2018 / 16:26
1

You can compare the table with itself for the highest priority:

SELECT *
  FROM tabela t
 WHERE t.prioridade = (SELECT MAX(t2.prioridade)
                         FROM tabela t2
                        WHERE t2.origem = t.origem
                          AND t2.destino = t.destino)
    
12.02.2018 / 21:08