List:General Discussion« Previous MessageNext Message »
From:Waynn Lue Date:August 6 2008 11:13pm
Subject:Re: Picking the better query (join vs subselect)
View as plain text  
Out of curiosity, is it generally faster to do a sub query or do it in
code for something like this.

Schema of Settings table, where the PK is (ApplicationId, SettingId):
ApplicationId, SettingId, SettingValue

Select SettingValue from Settings where SettingId = 10 and
ApplicationId IN (select ApplicationId from Settings where SettingId =
22 and SettingValue = "1");

The other solution is to do the two queries separately then do the
filtering in code.

What's generally faster?

Waynn



On 8/6/08, Rob Wultsch <wultsch@stripped> wrote:
> On Wed, Aug 6, 2008 at 5:18 AM, Morten Primdahl <primdahl@stripped> wrote:
>> I've tried to find out if joins are preferred over subselects, but am not
>> able to come to a definite conclusion. I read that correlated subselects
>> are
>> bad, and I should go for the join, but I know the id of the record in the
>> outer query and can hard code that into the subselect (if that makes a
>> difference).
>>
>
> Sub queries should be avoided if possible in MySQL.
>
>
> --
> Rob Wultsch
> wultsch@stripped
> wultsch (aim)
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
>
Thread
Picking the better query (join vs subselect)Morten Primdahl6 Aug
  • Re: Picking the better query (join vs subselect)Rob Wultsch6 Aug
    • Re: Picking the better query (join vs subselect)Waynn Lue7 Aug
      • Re: Picking the better query (join vs subselect)walter harms8 Aug