Solved Select last changed Row for each group SQLITE
-
@filipdns Do you store the date and time of last update in each row?
-
@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.
-
@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 try with max (rowid) but I have only one row appear
-
@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
-
@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.
? -
@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...
-
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:30That is more clear?
-
@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.
-
@jsulm Ok thank you for your help any way, have nice day and happy Christmas ;-)
-
@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')
-
@filipdns Super!
Thanks! Happy Christmas to you too!