You are here: Re: SQL Sub-query syntax question.. « PHP SQL « IT news, forums, messages
Re: SQL Sub-query syntax question..

Posted by Bonge Boo! on 09/10/05 12:43

On 9/9/05 13:29, in article dfrv2r$90m$1@news.onet.pl, "Hilarion"
<hilarion@SPAM.op.SMIECI.pl> wrote:

> If you want to use the first query and get more data from the event_table,
> then
> don't forget to put the additional column names in GROUP BY clause (it's
> probably
> not needed in MySQL, but will make the query work also in other SQL engines
> and should be less dependant on the table structure).

Thanks for the code. Works like a charm. I also have a another table which
has enquiries about the events, again with the event_id as the foreign key.

What I was going to do was have the event, the number of enquiries and the
number of people who actually booked returned in a result.

To do this I'd need to join 3 tables, and also count from 2 different
tables. I don't think I can do this using the code example you've given me?
I try to extend the join and it messes up. The count() thing has me a little
confused. I'm choosing to count the number of unique results in the column
specified, and the GROUP BY statement "collapses" the table returned so we
only see rows for the "unique" values found I nthe GROUP By column?

Which would mean trying to add a 2nd count and group by would mess things up
completely?

So I thought the obvious thing to do would be to have 2 SQL queries, and
then perform a join on the tables they produce. I guessd I would be able to
temporarily "name" the result retrieved from the each query, then use those
names that to join the 2 results together. Google doesn't seem to bring up
anything relevant, nor does scanning the MYSQL manual.

The only thing I can found like this is to store the results of the first
query in a temporary table and then join that to to the 2nd query.

Is that sensible or am I missing a trick?

 

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

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