Engine23

MySQL result set for MIN and MAX that do not equal one another

I needed to get a mysql query where the MIN and MAX were set, but I could exclude any that the same.  I struggled a bit to figure out the proper syntax but my friend Tom B. from Gallup helped me out ( Thank you sir, that is one digital drop for you! ).  For those of you who may need to get this in the future...or maybe future me in a few weeks after I forget the syntax....here it is:

 SELECT SQL_CALC_FOUND_ROWS MIN(`entity_id`) as minResult, MAX(`entity_id`) as maxResult, `oms_id` FROM `customer_entity` WHERE `oms_id` IS NOT NULL GROUP BY `oms_id` HAVING minResult != maxResult 

Share: