List:General Discussion« Previous MessageNext Message »
From:Dotan Cohen Date:October 3 2011 10:24pm
Subject:In general, cheaper to INNER JOIN or two separate queries
View as plain text  
I need two fields from two different tables. I could either run two
queries, or a single INNER JOIN query:
	
$r1=mysql_query("SELECT fruit FROM fruits WHERE userid  = 1");
$r2=mysql_query("SELECT beer FROM beers WHERE userid  = 1");
--or--
$r=mysql_query("SELECT fruits.fruit, beers.beer FROM fruits INNER JOIN
beers ON fruits.userid = beers.userid WHERE beers.userid  = 1");

In general, which is preferable? I don't have access to the production
machine to benchmark at the moment, but which is best practice?
Thanks!

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com
Thread
In general, cheaper to INNER JOIN or two separate queriesDotan Cohen4 Oct