| List: | General Discussion | « Previous MessageNext Message » | |
| From: | Dotan Cohen | Date: | October 19 2011 5:27pm |
| Subject: | How to select the id of 2+ records for given user? | ||
| View as plain text | |||
Assuming a table such this: | ID | messageID | userID | |----|-------------|--------| | 1 | 345 | 71 | | 2 | 984 | 71 | | 3 | 461 | 72 | | 4 | 156 | 73 | | 5 | 441 | 73 | | 6 | 489 | 73 | | 7 | 483 | 74 | | 8 | 523 | 74 | | 9 | 723 | 74 | I need the second, third, fourth, etc messageID for each userID. So I would get a results table such as: | ID | messageID | userID | |----|-------------|--------| | 2 | 984 | 71 | | 5 | 441 | 73 | | 6 | 489 | 73 | | 7 | 483 | 74 | | 9 | 723 | 74 | I've tried playing with count and group by and limit, but I've not found a solution. I can easily get all the rows and then remove the rows that I don't need in PHP, but I'd still like to know if an all-MySQL solution is possible. Thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com
| Thread | ||
|---|---|---|
| • How to select the id of 2+ records for given user? | Dotan Cohen | 19 Oct |
| • Re: How to select the id of 2+ records for given user? | Michael Dykman | 19 Oct |
| • Re: How to select the id of 2+ records for given user? | Derek Downey | 19 Oct |
| • Re: How to select the id of 2+ records for given user? | Basil Daoust | 20 Oct |
| • Re: How to select the id of 2+ records for given user? | Derek Downey | 20 Oct |
| • Re: How to select the id of 2+ records for given user? | Dotan Cohen | 20 Oct |
| • Re: How to select the id of 2+ records for given user? | Dotan Cohen | 20 Oct |
| • Re: How to select the id of 2+ records for given user? | hsv | 20 Oct |
| • Re: How to select the id of 2+ records for given user? | Dotan Cohen | 21 Oct |
