I have two tables :
main : id_main, field1, filter
main_logs (50 millions lines) : auto inc, id_main, path
I looking for the following results : id_main, field1, most common path
I tried the following query :
select id_main,
field1,
(select path, count(*) as cpt
from main_log
where main_log.id_main=main.id_main group by path order by cpt desc limit 1)
from main
where filter in (1,3,5);
Mysql return : Operand should contain 1 column(s)
If I remove path, results are correct, but I miss the path value.
select id_main,
field1,
(select path, count(*) as cpt
from main_log
where main_log.id_main=main.id_main group by path order by cpt desc limit 1)
from main
where filter in (1,3,5);
I don't need the result of count(*) but I need it for the "order by"
How can I write this query to get my results ? Thanks
main
id_main | field1 | filter
1 | red | 1
2 | blue | 3
3 | pink | 1
main_logs
autoinc | id_main | path
1 | 1 | home1
2 | 1 | home2
3 | 1 | home2
4 | 2 | house2
5 | 2 | house7
6 | 2 | house7
7 | 3 | casee
expected result
id_main | fields1 | most common path
1 | red | home2
2 | blue | house7
3 | pink | casee