kmillecam — 2010-05-03T12:57:41-04:00 — #1
I can't figure out what's wrong with this query. Can you help?
SELECT tid, uid, points, FROM_UNIXTIME(time_stamp),
WHERE YEAR(FROM_UNIXTIME(time_stamp)) = 2010
AND MONTH(FROM_UNIXTIME(time_stamp)) = 5
AND description LIKE '%inactivity%';
swampboogie — 2010-05-03T13:45:26-04:00 — #2
remove the comma after the last column in the select list
spacephoenix — 2010-05-03T15:59:41-04:00 — #3
kmillecam, a little tip about the layout of queries, if you lay them out like below (using your own one as an example), it doesn't run any faster or slower but it makes it easier to spot mistakes like stray , and you'll find queries more readable, especially when you have more complex queries involving joins and sub-queries.
YEAR(FROM_UNIXTIME(time_stamp)) = 2010
MONTH(FROM_UNIXTIME(time_stamp)) = 5
description LIKE '%inactivity%'
kmillecam — 2010-05-04T18:34:43-04:00 — #4
Thank you both so much for your help with this issue!
I appreciate your willingness to help (and teach) those of us who struggle with these concepts.
r937 — 2010-05-04T19:30:38-04:00 — #5
you have the WHERE clause connectors on separate lines, but not the SELECT clause connectors
although i must admit i like your leading commas
leading ANDs and ORs work just as well
r937 — 2010-05-04T19:34:27-04:00 — #6
kmillecam, the way you are isolating the rows for a particular month will work correctly but can potentially be very slow
assuming there's an index on the time_stamp column, this will be a lot faster...
WHERE time_stamp >= UNIX_TIMESTAMP('2010-05-01')
AND time_stamp < UNIX_TIMESTAMP('2010-06-01')