My server database took too long to run two sql queries by separate thread. I’m doing so in PHP:
$First=mysql_query("SELECT `ID`,`Country` FROM `Users` WHERE `IP`='".$ip."'",$connection);
$row=mysql_fetch_assoc($First);
$id=$row['ID'];
$ucountry=$row['Country'];
$opt=mysql_query("SELECT Size,Paper,Zip FROM Tools WHERE (Users LIKE '%".$id."%') OR (Users LIKE '".$id."%') OR (Users LIKE '%".$id."') OR (Users LIKE '".$id."') OR (Users LIKE 'All users') OR (Country LIKE '".$ucountry."') OR (Country LIKE 'All countries')",$connection);
How to do all this stuff in mysql in just one query?
I tried this:
SELECT (SELECT `ID` FROM `Users` WHERE `IP`='xx.xx.xx.xx' ) AS UID, (SELECT `Country` FROM `Users` WHERE `IP`='xx.xx.xx.xx' ) AS UCountry, (SELECT Size,Paper,Zip FROM Tools WHERE (Users LIKE CONCAT('%#',UID,'#%')) OR (Users LIKE CONCAT('#',UID,'#%')) OR (Users LIKE CONCAT('%#',UID,'#')) OR (Users LIKE CONCAT('#',UID,'#')) OR (Users LIKE 'All users') OR (Country LIKE UCountry) OR (Country LIKE 'All countries'))
If you need to be sure that only the first row is used on your select from users to be replicated in the SQL you’ll need to JOIN to an inline query