Jump to content

[SOLVED] More complicated conditionals


Edgewalker81

Recommended Posts

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)

Link to comment
https://forums.phpfreaks.com/topic/165963-solved-more-complicated-conditionals/
Share on other sites

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.

 

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.