Re: Can you SUM(IF) from two different tables at the same time?
| From: | Hugh Bothwell | Date: | Wed, 29 May 2002 02:41:55 +0000 |
| Subject: | Re: Can you SUM(IF) from two different tables at the same time? | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-19481@lists.php.net to get a copy of this message | ||
"Richard Davey" <rich@fatal-design.com> wrote in message
news:20020528225801.70043.qmail@pb1.pair.com...
>
> In the 5th line I changed "thread.id" to "thread.threadid" so the name was
> correct but the same error occurs.
Ok, I was guessing at your field names...
> to give a perfectly satisfactory result but have no idea if this is
> perversing SQL again or not!
(grin)
When retrieving information from a database, you
should expect to get a variable number of records
where each record has the same structure.
Instead, you were hard-coding a query to get
a single record with information about a number
of different groups. If you wanted to change
the number of groups returned, you would have to
change the structure of the query.
By getting a record for each group, the
structure of the query does not change if
you decide to look at a different number
of groups - just the data you give to
the WHERE clause.
> (it at least makes more sense now I guess).
> As soon as I add the "where IN" clause it errors.
umm... try putting the WHERE clause before the GROUP BY?
> Can anyone recommend ANY good books on SQL
> query design? I don't want (or care) about database
> administration, I just want to know what constitutes a
> good database design and lots and lots of query
> examples/tutorials.
try a Google search for 'database normalization tutorial';
that should get you started.
also check out the documentation at www.mysql.com