So i have this table:

numb_1 | numb_2 | numb_3
------------------------ 
   5   |    5   |   5
   1   |    5   |   5
   2   |    2   |   3
   5   |    3   |   6
   5   |    4   |   7

how do i find the most common value in the 3 fields?
so for the example above it would give me 5

Use two UNION's to turn it into a single list, then GROUP, COUNT and ORDER.

Hello,
SOmething like this should give you the number of times each value shows up with the value and number of times it was seen. Then just select the first row with Limit 1.

select 
data1.my_value
sum(my_counter)
from
(select
numb_1 as my_value,
1 as my_counter 
from 
mytable
union
select
numb_2 as my_value,
1 as my_counter 
from 
mytable
union
select
numb_3 as my_value,
1 as my_counter 
from 
mytable
) as data1 
group by data1.my_value

thank you very much, i got it!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.