Edgewalker81 Posted July 14, 2009 Share Posted July 14, 2009 I'm trying to offload some of my PHP control structure "workload" to MySQL for scalability. Here is a pseudocode example of what I'm trying to do SELECT the first 20 records from event_dates that have a date>today OR the next three weeks, whichever is the larger set I know how I'd write those queries individually, but not sure how to combine them to avoid having to grab 2 sets, waste time comparing them via PHP, and throw one set away. (MySQL 5.0 as part of WAMP) Quote Link to comment https://forums.phpfreaks.com/topic/165963-solved-more-complicated-conditionals/ Share on other sites More sharing options...
Edgewalker81 Posted July 14, 2009 Author Share Posted July 14, 2009 Ok, I found my solution on my own, and it's the "UNION" statement. I assumed that UNION would return duplicate rows if the results overlap. It does not. It's pretty simple really. You just UNION both queries (one by date and one by quantity) and you'll wind up with the larger of the two as the final result. Quote Link to comment https://forums.phpfreaks.com/topic/165963-solved-more-complicated-conditionals/#findComment-875311 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.