-1

I have 2 columns one having month and another year , I want to get all the records greater than that month and year

I cannot use date functions as those columns are of integer type, It gives incorrect results

How can I get records greater than that month and year

For example How can I get events which took place after february 2017

san
  • 237
  • 7
  • 19

3 Answers3

3

What about this approach:

SELECT * FROM table WHERE CONCAT(year, month) > 201702
Jan Rydrych
  • 2,188
  • 2
  • 13
  • 18
-1

WHERE CONCAT(year, month) > 201702

probably you have also some php code inside so:

$date = strtotime('2018-01-01 01:01:01');
$sql =  'SELECT * FROM YOUR_TABLE 
          WHERE CONCAT(year, month) > ' . date('Ym', $date);
Piotr Pasich
  • 2,639
  • 2
  • 12
  • 14
-1
SELECT * FROM events WHERE CONCAT(year,month) >= 201702

or without CONCAT

SELECT * FROM events WHERE( month > 2 AND year =2017) OR (year > 2017) 
Maciej__
  • 159
  • 7