RE: [PHP-DB] Can't get left join to work
| From: | Rick Emery | Date: | Fri, 08 Feb 2002 14:14:15 +0000 |
| Subject: | RE: [PHP-DB] Can't get left join to work | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-16676@lists.php.net to get a copy of this message | ||
Actually, the && is the same as "and". So it could be written as:
> mysql> select e.id,fname,sum(m.miles) from employees e
> -> left join mileage m on m.id=e.id and month(trip_date)=3
> -> and substring(year(m.trip_date),3,2) = '02'
> -> group by e.id;
I'm just lazy...easier to hit & twice than type out "and".
You were on the right path. You simply needed to move the conditional
statements from the WHERE to the JOIN clause. I learned that stuff from
reading the comments/answers on the list from DuBoise, Zawodny, and others.
-----Original Message-----
From: paul wilczynski [mailto:paul.wilczynski@shaws.com]
Sent: Friday, February 08, 2002 5:42 AM
To: Rick Emery
Subject: Re: [PHP-DB] Can't get left join to work
Thank you! I'm obviously going to have to read up on that 'on ... &&'
syntax -
it's not something I'm familiar with.
Paul
Rick Emery wrote:
> And the answer is:
>
> mysql> select e.id,fname,sum(m.miles) from employees e
> -> left join mileage m on m.id=e.id && month(trip_date)=3
> -> && substring(year(m.trip_date),3,2) = '02'
> -> group by e.id;