Page 1 of 1

Selecting multple tables or DB

Posted: Tue Dec 07, 2010 10:03 pm
by hallsofvallhalla
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

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>";
	
	}
this will search all 3 tables and echo out all who meet the requirements in one nice query :)

Re: Selecting multple tables or DB

Posted: Thu Dec 16, 2010 10:02 pm
by ConceptDestiny
Do those tables selected not have to have the same number of columns?

Re: Selecting multple tables or DB

Posted: Tue Dec 21, 2010 4:27 pm
by hallsofvallhalla
yes they do actually.