OT: MySQL syntax help

Darrin Chandler dwchandler at stilyagin.com
Tue May 16 17:28:21 MST 2006


On Tue, May 16, 2006 at 05:22:34PM -0700, Kevin Brown wrote:
> >>>I need a query to pull every row from Table2 where the "kernel" field
> >>>matches ANY row in Table1.  Any ideas???
> >>See docs for EXISTS
> >
> >PERFECT!  Thanks Darrin!  Something like this will work.
> >
> >SELECT *
> >FROM Table2
> >WHERE EXISTS
> >  (select *
> >    from Table1
> >    where kernel = Kernel);
> 
> SELECT *
> FROM Table2
> WHERE EXISTS
>   (select kernel
>     from Table1
>     where kernel = Kernel);
> 
> Try to avoid the * if you don't really need to select all the data from 
> all the fields of a table.  It might not seem like much, but it adds up 
> as the tables grow larger.

It shouldn't matter at all in a WHERE EXISTS subquery. If it does then
you need to switch database software.

Selecting only the needed columns in other places is a great thing, most
notably when your server and client aren't on the same machine but still
good for localhost.

-- 
Darrin Chandler            |  Phoenix BSD Users Group
dwchandler at stilyagin.com   |  http://bsd.phoenix.az.us/
http://www.stilyagin.com/  |


More information about the PLUG-discuss mailing list