I recently asked a question:
search for last 24h lines that repeat the most (MySQL)
And it was answered, I now have another question. I do the following to find from
and to
of the most repeated lines of the last 24h, but there is a problem, from
and to
is not the data I needed, it is like the id of another table, of the "name" field 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'm trying to erroneously as you can see above. But I already have the result I want with the PHP code below, my question 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"]
);
}