Sorting the number of mysql subquery statistics causes the query to be too slow

select id, (select sum ( test_field ) from test2 where test_id = test2_id) as total from test order by total limit 5
does a sql like this cause slowness? is there any solution

Oct.16,2021

you have only one piece of data in this query. Why do you still use subqueries and order by??


well, that's all I can write.


use JOIN

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3bb5a-2c2ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3bb5a-2c2ab.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?