Re: Query help
| From: | Dobromir Velev | Date: | Mon, 19 Nov 2001 14:45:15 +0000 |
| Subject: | Re: Query help | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-14436@lists.php.net to get a copy of this message | ||
Hi,
I haven't seen the previous posts so I'm not sure want you want to do, but
it looks like that you need to specify a join condition. If freerooms.room
and booking.room are the corresponding fields from your table the query
should look something like this
SELECT count(freerooms.room), WEEK(MAX(booking.date),1),
WEEK(MIN(booking.date),1) as total FROM freerooms LEFT JOIN booking ON
freerooms.room=booking.room
USING(room);
or
SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1)
FROM freerooms f, booking b
WHERE f.room=b.room
Hope this helps
Dobromir Velev
-----Original Message-----
From: Matt Williams <matt@yewlands.com>
To: Andrey Hristov <ahristov@icygen.com>
Cc: php-db@lists.php.net <php-db@lists.php.net>
Date: Monday, November 19, 2001 10:26
Subject: RE: [PHP-DB] Query help
>This doesn't work either.
>
>SELECT count(freerooms.room), WEEK(MAX(booking.date),1),
>WEEK(MIN(booking.date),1) as total FROM freerooms LEFT JOIN booking
>USING(room);
>
>> > All good so far
>> > now if I run this
>>
>> > SELECT count(f.room),WEEK(MAX(b.date),1), WEEK(MIN(b.date),1)
>> FROM freero
>> > oms f, booking b;
>> > ->+---------------+---------------------+---------------------+
>> > | count(f.room) | WEEK(MAX(b.date),1) | WEEK(MIN(b.date),1) |
>> > +---------------+---------------------+---------------------+
>> > | 24817 | 48 | 40 |
>> > +---------------+---------------------+---------------------+
>> >
>
>What I have found is
>
>freerooms.room has 83 rows and booking has 299.
>The value returned for count(f.room) is these two figures multiplied.???
>
>Why would it do this?
>And how can I get it to return the real value only
>
>Regards
>
>M:
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
>For additional commands, e-mail: php-db-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>