0
I asked a question recently:
Find lines of the last 24 hours that repeat the most (Mysql)
And it was answered, now I have another question. I do the following to seek from
and to
of the most repeated lines of the last 24 hours, but there is a problem, from
and to
is not the data that needed, is like the id of another table, and then needs the field "name" of another table.
SELECT nome, idade
FROM other_table
WHERE myid = `from`, myid = `to`(SELECT `from`, `to`, COUNT(*) AS num_clicks
FROM my_rank
WHERE my_rank_data >= NOW() - INTERVAL 1 DAY
GROUP BY `from`, `to`
ORDER BY num_clicks DESC LIMIT 20);
I am trying wrongly as you can see above. But I already get the result I want with the PHP code below, my doubt is if it is possible to achieve the same result only with the query.
$resultQueryClicks = mysqli_query($con, 'SELECT `from`, `to`, COUNT(*) AS num_clicks
FROM moeda_rank
WHERE data_clique >= NOW() - INTERVAL 365 DAY
GROUP BY `from`, `to`
ORDER BY num_clicks DESC LIMIT 20');
$rankMoeda = array();
while($aux = mysqli_fetch_assoc($resultQueryClicks)) {
$nameFrom = mysqli_query($con,'SELECT xml FROM moeda WHERE moeda = '.$aux["from"]);
$nameTo = mysqli_query($con,'SELECT xml FROM moeda WHERE moeda = '.$aux["to"]);
$auxFrom = mysqli_fetch_assoc($nameFrom);
$auxTo = mysqli_fetch_assoc($nameTo);
$rankMoeda[] = array(
"from" => $auxFrom["xml"],
"to" => $auxTo["xml"]
);
}