Sql. table, organized date and time

Asked

Viewed 96 times

0

I have an sql table that will contain appointment, date and time. I keep the three based on ID. I have a question about the date and time

id = 0; data 28/08/2018 - 13:11h
id = 1; data 26/08/2018 - 17:10h
id = 2; data 25/08/2018 - 11:15h

I want to organize the table this way:

id = 0; data 25/08/2018 - 11:15h
id = 1; data 26/08/2018 - 17:10h
id = 2; data 28/08/2018 - 13:11h

Because when I schedule a time and a date, I might have a notion to set the next alarm based on id 0. I’m having trouble with this, because when I save a date and a time, I don’t know which to call

  • I didn’t understand your question... the time is not associated with a specific ID? How do you plan to organize times by different Ids?

  • Actually I wanted to put the dates in the DESC form on the table, so that the date would always be close to the current date, how to do this?

  • instead of changing the id, because you don’t create a field for exhibition order?

  • Could you exemplify? I’m having doubts about how to do this

1 answer

0


I believe you need an SQL query as you yourself described with DESC in the "date field":

SELECT * FROM nome_da_tabela ORDER BY data DESC

But from what I understand you want to update the line to change the ID according to the date, is that it? . If it is, I do not advise doing this directly in the database table but programmatically with a loop adding a new column and identifying the order (0,1,2,etc...), or even changing the business rule to use the query ordered by the date.

I hope it helps!

Hug, Herbert.

  • Changing the business rule, as I would SELECT in the table, always searching for the most current date, and turning into an integer?

Browser other questions tagged

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