Mike McGonagle wrote:
> Oh, I forgot to mention (if it matters), the "MAIN" table has about 3000
> rows in it, while the "LIST" table has about 60000 rows.
> Mike
> 
> 
> On Mon, Mar 3, 2008 at 3:32 PM, Mike McGonagle <[EMAIL PROTECTED]> wrote:
> 
>> Hello all,
>> I was working with some queries last night, and ran accross something that
>> I don't quite understand. Basically, this is what I have...
>>
>> ***************************
>>
>> CREATE TABLE MAIN (
>> id integer primary key autoincrement not null,
>> name varchar(30),
>> [other fields left out, as they are not used]
>> );
>>
>> CREATE TABLE LIST (
>> mid integer,
>> ord integer,
>> data float
>> );
>>
>> -- Compound Query
>> SELECT data FROM LIST WHERE mid = (SELECT id FROM MAIN WHERE name =
>> "something") ORDER BY ord;
>>
>> -- Individual Queries
>> SELECT id FROM MAIN WHERE name = "something";
>> SELECT data FROM LIST WHERE mid = id_as_returned_above;

This just screams inner join.

SELECT data FROM LIST l
INNER JOIN MAIN m ON l.mid = m.id
WHERE m.name = "something";

My advice is ALWAYS to avoid subselects unless you ABSOLUTELY have 
to use them.


-- 
Scott Baker - Canby Telcom
RHCE - System Administrator - 503.266.8253
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to