Get only 1 of each journey

1

Well, I have a table designated by tabelajornadas .

In it, I have several records, and in which I have the column jornada , which is of type int .

At the same time, they contain several records with the same number in the working column.

What I want to do is select , which gives me only 1 record of each day, in ascending order of the day.

How can I do this?

    
asked by anonymous 25.08.2017 / 15:04

3 answers

0

As you have not described how the table (s) you want help is modeled, you can select only one record with the same day number

SELECT param1, param2, param3 FROM myTable WHERE jornada = "minhaJornada" ORDER BY param1 ASC LIMIT 1

In this way, you will be selecting param1, param2, param3 from the myTable table where the working column equals a working day specified - which is sorted by param1 and by limiting the search to only one result - exactly as described in your doubt.

    
25.08.2017 / 15:10
0

You can use the NOT EXISTS clause to check if there are codes greater than the current one for the specific day:

SELECT tj.*
  FROM tabelajornadas tj
 WHERE NOT EXISTS(SELECT 1
                    FROM tabelajornadas tj2
                   WHERE tj2.jornada = tj.jornada
                     AND tj2.codigo < tj.codigo)
    
25.08.2017 / 15:25
0

What you need is to group the records together. Then you can use the GROUP BY clause. Here is an example based on your schema:

SELECT
    jornada
FROM
    tabelajornadas
GROUP BY
    jornada
ORDER BY
    jornada;

The GROUP BY groups the result by the columns you enter. You can read more about it here: link

    
25.08.2017 / 15:29