[thelist] sql cross table exclusion??

rudy r937 at interlog.com
Wed Aug 28 22:34:01 CDT 2002


> select user.userid, user.name
>       , usercar.cartype
>  from user, usercar
>   where usercar.userid = user.userid
>    and usercar.cartype not in ('Ford', 'Porche');

two problems with that, jon

first, cartype is in the car table, missing from your query
(haste maketh waste, as i rediscover quite frequently myself)

secondly, and more insidious, is a logical trap that isn't immediately
obvious

if Fred has a Lada, a Ford, and a Porsche, Fred will be listed because the
Lada satisfies the "not in ('Ford', 'Porche')" condition

the problem was to list Fred only if he didn't have a Ford or a Porsche

negatives in sql are thorny, aren't they?


rudy




More information about the thelist mailing list