mysql query for high values in table -


i have following data in results table:

 +-----+-----+-----+-----+-----+-----+ |   |  b  |  c  |  d  |  e  |  f  | +-----+-----+-----+-----+-----+-----+ | 100 | 140 | 120 | 130 | 160 | 150 | | 200 | 243 | 374 | 435 | 674 | 987 | | 312 | 324 | 123 | 456 | 378 | 645 | +-----+-----+-----+-----+-----+-----+ 

what sort of select statement can me highest 5 values results table?

what sort of select statement can me highest 5 values results table?

the fact each column treated identically suggests schema denormalised. operation simplified if data normalised, such columns merged (but additional column created indicate column each record originated).

however, things stand, can use union:

  (select col results order col desc limit 5) union   (select b col results order col desc limit 5) union   (select c col results order col desc limit 5) union   (select d col results order col desc limit 5) union   (select e col results order col desc limit 5) union   (select f col results order col desc limit 5) order col desc limit    5 

see on sqlfiddle.


Comments