Re: Help with 3 tables select
FFMG <FFMG.2zmfl0@no-mx.httppoint.com> wrote in
<FFMG.2zmfl0@no-mx.httppoint.com>:
> Pavel Lepin Wrote:
>> ....you should use JOINs. Read about JOIN syntax in MySQL
>> Reference Manual.
>
> But why would a JOIN be better than a multiple select?
"Multiple select?"
> SELECT TABLE_C.* FROM TABLE_A, TABLE_B, TABLE_B
> WHERE
> TABLE_C.permission = TABLE_B.permission
> AND
> TABLE_B.userID = TABLE_A.userID
> AND
> TABLE_A.username = 'x'
You haven't read the chapter on JOINs, did you? I'll quote
from MySQL 5.0 Reference Manual, 12.2.7.1 for you:
INNER JOIN and , (comma) are semantically equivalent in
the absence of a join condition: both produce a Cartesian
product between the specified tables (that is, each and
every row in the first table is joined to each and every
row in the second table).
So in a very real sense, this query still uses JOINs. You're
simply using WHERE clause instead of join condition to
filter the result set.
> And in my case get the same result, what would be the
> 'better' way of selecting the permissions?
The result set will be the same. Some people find the syntax
with explicit JOINs and join conditions less obscure and
more to the point. YMMV. I remember a reasonably
knowledgeable person saying mysqld might have a harder time
optimising queries using WHERE clause instead of join
conditions, but I'm not a query optimisation expert myself,
so don't quote me on that. If in doubt, run benchmarks.
--
"I can't help but wonder if you... don't know a hell of a
lot more about practically every subject than Solomon ever
did." |