0

I'm trying to select data from a specific table in my database, but I want to be able to only view the last 3 days worth of data, I have the following code but for some reason I can't get it to work.

SELECT * FROM demands WHERE t.date >= DATE_ADD(CURDATE(), INTERVAL -3 DAY)
Dharman
  • 30,962
  • 25
  • 85
  • 135

1 Answers1

3

You may avoid usage of DATE_ADD() at all:

SELECT * FROM demands as t WHERE t.date >= (CURDATE() - INTERVAL 3 DAY)

As @OGHaza mentioned, you specified column with alias to nowhere: t.date should be just date (note that it is a reserved word, so you should use backticks around it in this case) or demands should be specified with an alias like demands as t.

BlitZ
  • 12,038
  • 3
  • 49
  • 68