chantown Posted April 27, 2009 Share Posted April 27, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/155775-how-to-limit-within-a-select/ Share on other sites More sharing options...
revraz Posted April 27, 2009 Share Posted April 27, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/155775-how-to-limit-within-a-select/#findComment-820280 Share on other sites More sharing options...
fenway Posted April 28, 2009 Share Posted April 28, 2009 The answer is "no" -- what's wrong with a union? Quote Link to comment https://forums.phpfreaks.com/topic/155775-how-to-limit-within-a-select/#findComment-821218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.