Jump to content

PHP Selecting only 10 rows from each of multiple WHERE conditions


DillyDong

Recommended Posts

Hi all, sorry, I know the title is ambiguous, but I wasn't sure exactly how to explain it.

Anyway,

Say I have the following code:

[code]'SELECT * FROM `table` WHERE `list_number` IN (1,3,5)[/code]

Now, let's say that there are 20 rows for each matching `list_number` criteria (ie, There are 20 rows where `list_number` = 1, 20 rows where `list_number` = 3, and 20 rows where `list_number` = 5).

What I would like to know is, how would I tell the MySQL query to get only 10 (in order or random, doesn't matter) rows for each `list_number`? I thought that LIMIT only worked for the entire query, not per where condition.

Any help is appreciated! Thank you!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.