Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Select last changed Row for each group SQLITE
Forum Updated to NodeBB v4.3 + New Features

Select last changed Row for each group SQLITE

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 4 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F filipdns

    @jsulm the problem is I can have some change for one or two of them before have change for others but I need to have last change for each, that mean with the good select only 1 row for each cars appear.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #5

    @filipdns You're adding new row each time you change something? Do you have an auto increment ID? If so you can simply take the row with highest ID. But I don't know your database set-up.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    F 1 Reply Last reply
    0
    • F Offline
      F Offline
      filipdns
      wrote on last edited by
      #6

      I try with max (rowid) but I have only one row appear

      jsulmJ 1 Reply Last reply
      0
      • jsulmJ jsulm

        @filipdns You're adding new row each time you change something? Do you have an auto increment ID? If so you can simply take the row with highest ID. But I don't know your database set-up.

        F Offline
        F Offline
        filipdns
        wrote on last edited by filipdns
        #7

        @jsulm said in Select last changed Row for each group SQLITE:

        @filipdns You're adding new row each time you change something? Do you have an auto increment ID? If so you can simply take the row with highest ID. But I don't know your database set-up.

        I add sometime but also I make update only, yes auto increment ID is done

        JonBJ 1 Reply Last reply
        0
        • F filipdns

          @jsulm said in Select last changed Row for each group SQLITE:

          @filipdns You're adding new row each time you change something? Do you have an auto increment ID? If so you can simply take the row with highest ID. But I don't know your database set-up.

          I add sometime but also I make update only, yes auto increment ID is done

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #8

          @filipdns
          Have you looked at https://stackoverflow.com/questions/1964233/does-sqlite3-support-a-trigger-to-automatically-update-an-updated-on-datetime or https://alvinalexander.com/android/sqlite-default-datetime-field-current-time-now, depending on your requirements.
          ?

          1 Reply Last reply
          1
          • F filipdns

            I try with max (rowid) but I have only one row appear

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #9

            @filipdns said in Select last changed Row for each group SQLITE:

            I try with max (rowid) but I have only one row appear

            My understanding was that you need that one last edited row. Now I'm lost...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • F Offline
              F Offline
              filipdns
              wrote on last edited by
              #10

              I understand that you can be lost ;-)

              I try to be more clear with example:
              columns are car, date of drive, time drive, total time of use.

              after each time a car drive, I insert the time use of the concerning car and I need table showing the last value of each like table bellow:

              car 1 drive 1h today total time is 70:50
              car2 drive 2h30 yesterday total time is 50:25
              car 3 drive 1h yesterday total time is 25:20
              car4 drive 2h today total time is 10:30

              That is more clear?

              jsulmJ 1 Reply Last reply
              0
              • F filipdns

                I understand that you can be lost ;-)

                I try to be more clear with example:
                columns are car, date of drive, time drive, total time of use.

                after each time a car drive, I insert the time use of the concerning car and I need table showing the last value of each like table bellow:

                car 1 drive 1h today total time is 70:50
                car2 drive 2h30 yesterday total time is 50:25
                car 3 drive 1h yesterday total time is 25:20
                car4 drive 2h today total time is 10:30

                That is more clear?

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #11

                @filipdns Then you will need a bit more complex SELECT query. I don't have time to find the right one. I think you could use GROUP BY.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                F 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @filipdns Then you will need a bit more complex SELECT query. I don't have time to find the right one. I think you could use GROUP BY.

                  F Offline
                  F Offline
                  filipdns
                  wrote on last edited by
                  #12

                  @jsulm Ok thank you for your help any way, have nice day and happy Christmas ;-)

                  F 1 Reply Last reply
                  0
                  • F filipdns

                    @jsulm Ok thank you for your help any way, have nice day and happy Christmas ;-)

                    F Offline
                    F Offline
                    filipdns
                    wrote on last edited by filipdns
                    #13

                    @filipdns it's working with group thanks a lot !!

                    SELECT max(rowid), registration,timedrive,totaltime FROM time_log group by registration order by rowid desc')

                    jsulmJ 1 Reply Last reply
                    0
                    • F filipdns

                      @filipdns it's working with group thanks a lot !!

                      SELECT max(rowid), registration,timedrive,totaltime FROM time_log group by registration order by rowid desc')

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #14

                      @filipdns Super!
                      Thanks! Happy Christmas to you too!

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved