You are here: Re: left join issue « PHP SQL « IT news, forums, messages
Re: left join issue

Posted by KrunoG on 11/15/06 07:27

"Pierre" <pierre.ducrot@wanadoo.fr> wrote in message
news:1hou1lo.hq2egy1ia4v2oN%pierre.ducrot@wanadoo.fr...
> Hi there,
>
> I have an issue with several LEFT JOIN ... ON like the one postes below.
> The query below executes correctly on MySQL 4.1.16-standard but fails on
> the same tables on a 5.0.19-standard server.
>
> erro: #1054 - Unknown column 'c.id' in 'on clause'
>
> --SELECT c.id, c.nom, c.prenom, t.Tickets
> FROM clients c, inscriptions i
> LEFT JOIN (
> SELECT COUNT( * ) Tickets,
> CLIENT FROM tickets
> GROUP BY CLIENT
> ) AS t ON c.id = t.client
> WHERE i.client = c.id
> ORDER BY c.nom, c.prenom
>

/*try like this:

select c.id, c.nom, c.prenom, t.tickets
from clients c left join inscriptions i on i.client =c.id
left join tickets t on c.id=t.client
order by c.nom, c.prenom*/

I just don't see how could any of sql's recognize this query, 'cause there
is no way that you could successfully join "count (*) of something" with a
field in another table. Review the logic of agregate functions (count, sum,
avg...)

If you have doubles in those 'tickets' table (I suppose that one customer
could have more than one of tickets) join it like this:

select c.id, c.nom, c.prenom, t.tickets
from clients c left join inscriptions i on i.client =c.id
left join tickets t on c.id=(select tk.client
from tickets tk
group by tk.client)
order by c.nom, c.prenom*/


BR
Kruno

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация