Reputation: 1475
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
ORDER BY id ASC
WHERE unixtime <= CURDATE() LIMIT 10;
or
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
ORDER BY id ASC
WHERE unixtime < CURDATE() LIMIT 10;
all phpAdmin is telling me is:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE unixtime <= CURDATE() LIMIT 10' at line 1
Upvotes: 0
Views: 1626
Reputation: 15683
Try the following:
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
WHERE UNIX_TIMESTAMP(timestamp) <= CURDATE()
ORDER BY id ASC LIMIT 10;
Upvotes: 1
Reputation: 247700
You have the ORDER BY
and WHERE
clauses reversed.
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
WHERE unixtime < CURDATE()
ORDER BY id ASC LIMIT 10;
or
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
WHERE unixtime <= CURDATE()
ORDER BY id ASC LIMIT 10;
I just realized that part of your issue because you are referencing an alias in your WHERE
clause.:
WHERE UNIX_TIMESTAMP(timestamp) <= CURDATE()
or
WHERE UNIX_TIMESTAMP(timestamp) < CURDATE()
Upvotes: 2
Reputation: 1042
try this
SELECT id, content, UNIX_TIMESTAMP(timestamp) AS unixtime
FROM data
WHERE (UNIX_TIMESTAMP(timestamp)) < CURDATE() ORDER BY id ASC LIMIT 10;
Upvotes: 1