Jump to content

how to LIMIT within a select.


chantown

Recommended Posts

Hi, is there anyway to set limits within ONE select query?

 

SELECT * FROM my_table WHERE

(date = '123') <<< SET A LIMIT of 4 here.

OR

(name = 'sun') << SET A LIMIT of 3 here.

 

I know that it's possible to break this into 2 SELECTS and UNION them. But is there a way to keep 1 query, and set limits between the "ORs"?

 

thank you!

 

 

Link to comment
Share on other sites

I think you may misunderstand what this result will produce.

 

It will return rows that have 123 in date OR sun in name, so you can get mixed rows.  Your LIMIT logic based on one or the other is flawed and wouldn't work.

 

Run the query and see the results and you'll notice rows with both values appear.

 

Or do you want the first 4 dates with 123 and the first 3 names with sun?

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.