Selecting multple tables or DB
Posted: Tue Dec 07, 2010 10:03 pm
didn't know if any of you use Union but if lets say you need to select every player, creature and every pet that has 100 gold and 10 hit points and players, creatures and pets are in different tables
this will search all 3 tables and echo out all who meet the requirements in one nice query 
Code: Select all
$result="SELECT name from players where hitpoints=10 AND gold =100 UNION ALL
SELECT name from creatures where hitpoints=10 AND gold =100 UNION ALL
SELECT name from pets where hitpoints=10 AND gold =100 UNION ALL
$result2=mysql_query($result) or die("Could not get result");
while($result3=mysql_fetch_array($result2))
{
echo $result3['name'] . "<br>";
}
