Reputation: 97
I have this struct of data stored in an SQLite DB:
I'm trying to get the records from the past 24 hours in a php code.
I use the following query that I found at similar questions:
SELECT temp FROM Sysstat
WHERE when >= date('now', '-1 days') AND when < date('now')
But it doesn't seem to work and gives error:
Warning: SQLite3::prepare(): Unable to prepare statement: 1, near "when": syntax error in..
Anyone could give me some advice?
Upvotes: 4
Views: 3337
Reputation: 175964
Enquote when
with "
or []
or backticks:
SELECT temp
FROM Sysstat
WHERE "when" >= date('now', '-1 days') AND "when" < date('now');
The list of keywords is so long that few people can remember them all. For most SQL code, your safest bet is to never use any English language word as the name of a user-defined object.
If you want to use a keyword as a name, you need to quote it.
"keyword" A keyword in double-quotes is an identifier.
- WHEN
Upvotes: 6