Re: LEFT joins

From: Date: Thu, 20 Jan 2005 20:46:43 +0000
Subject: Re: LEFT joins
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.db 
Request: Send a blank email to php-db+get-38241@lists.php.net to get a copy of this message
In general, you should not worry about faster query sintax, since mysql should (but i'm not sure) have an "optimizer" inside wich translate your sintax query in a "better" efficient one. Anyway, the "where" statement is perfectly equal to the "join" operator, it is called, in general, "theta-join" and in this case it is called "equi-join" (equi...because in the where statement you only compare attributes by the '=' operator). The only reason you want to use the "left-join", which is a particular case for a general "outer-join", is if you want to fill your result with "NULL" values rather than an empty records. Jochem Maas ha scritto:
OR.... SELECT b.fldName,
        b.fldEmail,
        b.fldCountryCode,
        d.fldCode as FCode,
        b.fldMobile,
        a.fldTime as Time,
        c.fldUsername as Username
FROM tblSubscribersChoices a LEFT JOIN tblUser c ON c.fldClientID = a.fldChoice LEFT JOIN tblSubscribers b ON b.fldID = a.fldClientID LEFT JOIN tc_countries d ON d.fldCode = b.fldCountryCode ORDER BY Username ASC
and if that works but doesn't give you repeat records try adding the DISTINCT keyword after SELECT. <snip>
Why are you so intrested in LEFT JOIN? I cn't help much since i don't
I'm not but his original query used JIONs and a LEFT JOIN is (IMHO) the easiest to understand. I didn't have the presence of mind to rewrite the query using a simple WHERE clause - hope your tip helps him. btw: can anyone say if the LEFT JOIN or the alternative WHERE statement (in general?) is faster?
know the schema of the db and i can't see clear the meaning of the tables in the query. Anyway try this: <SQL> SELECT b.fldName,
         b.fldEmail,
         b.fldCountryCode,
         d.fldCode as FCode,
         b.fldMobile,
         a.fldTime as Time,
         c.fldUsername as Username
FROM tblSubscribersChoices a, tblUser c, tblSubscribers b,
    tc_countries d
WHERE c.fldClientID = a.fldChoice AND b.fldID = a.fldClientID AND
    d.fldCode = b.fldCountryCode
ORDER BY Username ASC </SQL> Bye


« previous php.db (#38241) next »