Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: Help/guidance with a bit of tricky php/MySQL

date posted 4th March 2008 14:25

Depends on volumes of data.

With a sub-select, you are effectively running that query first and
using the results as the "IN" clause. Obviously, on a large table, that
"IN" could be pretty big. You wouldn't, for instance, write that query
and type in thousands of values in the IN clause - would you?

Run an explain plan and you will see table scans when using the IN
clause, where the join will use an index if one exists and is more
efficient to use.

So, I guess the IN clause is fine for small lists of returned values.
The join will be better if there are large volumes. The join will be
more scalable as the database grows - which should always be part of
your design decision.

The other syntax (in Oracle at least) is the EXISTS clause.

There's always more than one way to skin a cat - as they say :)

Dom Latter wrote:
> On Tuesday 04 March 2008 15:37:13 Duncan Glendinning wrote:
>
>> Question is, which is most efficient?
>
> [subselect vs. join]
>
> Everything I've read suggests that joining is much more efficient.
>
> You can try running an EXPLAIN on the queries for more info.
>
>
>

--
Dominic Raywood
Rubicon Computer Services Limited
W: http://rubiconcsl.com
E: [EMAIL REMOVED]
T: 08456 521 561 (+44 1823 698420)
F: 08456 521 561
M: 07050 204998 (+44 7811 252573)
Skype: RubiconCSL



Messages by Day
March 31st 2008
March 30th 2008
March 29th 2008
March 28th 2008
March 27th 2008
March 26th 2008
March 25th 2008
March 24th 2008
March 23rd 2008
March 22nd 2008
March 21st 2008
March 20th 2008
March 19th 2008
March 18th 2008
March 17th 2008
March 16th 2008
March 15th 2008
March 14th 2008
March 13th 2008
March 12th 2008
March 11th 2008
March 10th 2008
March 9th 2008
March 8th 2008
March 7th 2008
March 6th 2008
March 5th 2008
March 4th 2008
March 3rd 2008
March 2nd 2008
March 1st 2008


Messages by Month
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000