#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2

    Excluding a value in a query


    I'm trying to retrieve the top 3 userID's of a certain category from my database, which i have gotten to work with three different queries. Now i need to exclude my personal ID so it's not returned from any of the ranking queries.


    This is what I wrote for find the person in second place:
    Code:
    "SELECT MAX(uploads) AS maxuploads FROM `users` WHERE `uploads`<(SELECT MAX(uploads) FROM `users`)"
    I think my syntax is wrong, but I was testing this to exclude my ID:
    Code:
    AND `userID` NOT IN (SELECT `userID` FROM `users` WHERE `userID` = '$ignore'
    This is the whole statement I haven't gotten to work that should pull the second highest number of uploads excluding my ID:
    Code:
    "SELECT MAX(uploads) AS maxuploads FROM `users` WHERE `uploads`<(SELECT MAX(uploads) FROM `users`)AND `userID` NOT IN (SELECT `userID` FROM `users` WHERE `userID` = '$ignore'"
    Any help would be greatly appreciated.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    There's a much simpler query that should accomplish this, so I'm wondering if you already considered it and found a problem using it.
    Code:
    SELECT `userID`, `uploads` FROM `users` ORDER BY `uploads` DESC LIMIT 3
    Then make that exclude you from the consideration.

    Comments on this post

    • nbasso713 agrees
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    64
    Rep Power
    2
    Originally Posted by requinix
    There's a much simpler query that should accomplish this, so I'm wondering if you already considered it and found a problem using it.
    Code:
    SELECT `userID`, `uploads` FROM `users` ORDER BY `uploads` DESC LIMIT 3
    Then make that exclude you from the consideration.
    Req as always, thanks for the help . I swear i tried something similar a couple weeks ago, but i couldn't get it to work.

    Solution:

    Code:
    "SELECT `userID` FROM `users` WHERE userID NOT IN('$ignore') ORDER BY `views` DESC LIMIT 3"

IMN logo majestic logo threadwatch logo seochat tools logo