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
https://forums.phpfreaks.com/topic/155775-how-to-limit-within-a-select/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.