How to better perform a query split into subqueries in PHP In PHP I have made this query:

$getTrackID = $this-&gt;db-&gt;query("SELECT `id`,`uid` FROM `tracks`, `users` WHERE `time` &gt; CURDATE() - interval 1 year AND `uid`=`idu` AND `public` &gt; 0 ORDER BY RAND() LIMIT 10");
$TrackID = $getTrackID-&gt;fetch_assoc();
$id=$TrackID['id'];
$xid=$TrackID['uid'];


The problem is that it takes 1 sec to return the result. I saw this question and it seems better practice split big queries into subqueries.

Is this the case? To better perform should I need to use something like:

$getTrackTime = $this-&gt;db-&gt;query("SELECT `id`,`uid` FROM `tracks`, `users` WHERE `time` &gt; CURDATE() - interval 1 year AND `uid`=`idu`");
// Declare the rows array
$rows = array();
while($row = $getTrackTime-&gt;fetch_assoc()) {
    // Store the result into the array
    $rowsTime[] = $row;
}

$getTrackPublic = $this-&gt;db-&gt;query(sprintf("SELECT `%s`,`%s` FROM `tracks`, `users` WHERE `public` &gt; 0",$rowsTime['id'],$rowsTime['uid']));
$rows = array();
while($row = $getTrackPublic-&gt;fetch_assoc()) {
    $rowsPublic[] = $row;
}
...
Quickly get into the habit of writing your queries with some kind of formatting, proper joins, and with properly qualified column names. It makes it much easier to understand. E.g.:

SELECT t.id
     , t.uid
  FROM tracks t
  JOIN users u
    ON u.idu = t.uid
 WHERE t.time &gt; CURDATE() - INTERVAL 1 YEAR
   AND u.public &gt; 0 
 ORDER
    BY RAND() 
 LIMIT 10