Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Statement - condition within a condition?

I have a table where each record contains the time, represented by an hour column (int) and a minute column (int).For example:

**records |hours| mins**
record1 |  15 |  30
record2 |  12 |  25

I want to write a statement where only the records ahead of the current time will be displayed. So far, I have:

SELECT... 

WHERE hours >= hour(current_time)
AND
mins >= minute(current_time)
AND...

But this doesn't work because it needs both the hours and mins to be greater than the current hours and minutes. How do I write to that so that if the hours are the same, then the minutes are compared?

like image 355
user3007194 Avatar asked May 07 '26 21:05

user3007194


1 Answers

Do something like this:

WHERE  hours >= hour(current_time)
OR  (hours = hour(current_time) AND mins >= minute(currentime))
like image 140
shree.pat18 Avatar answered May 10 '26 16:05

shree.pat18