SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with my query

    Hi all,

    I can't figure out what's wrong with this query. Can you help?

    SELECT tid, uid, points, FROM_UNIXTIME(time_stamp),
    FROM userpoints_txn
    WHERE YEAR(FROM_UNIXTIME(time_stamp)) = 2010
    AND MONTH(FROM_UNIXTIME(time_stamp)) = 5
    AND description LIKE '%inactivity%';

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    remove the comma after the last column in the select list

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,029
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    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.

    Code MySQL:
    SELECT
          tid
        , uid
        , points
        , FROM_UNIXTIME(time_stamp)
    FROM
        userpoints_txn
    WHERE
        YEAR(FROM_UNIXTIME(time_stamp)) = 2010
    AND
        MONTH(FROM_UNIXTIME(time_stamp)) = 5
    AND
        description LIKE '%inactivity%'
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Utah, USA
    Posts
    110
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Kevin

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    if you lay them out like below ...
    fascinating

    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

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,263
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    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...
    Code:
    WHERE time_stamp >= UNIX_TIMESTAMP('2010-05-01')
      AND time_stamp  < UNIX_TIMESTAMP('2010-06-01')
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •