Counting the correct records.

From: Date: Wed, 23 Jan 2002 08:25:05 +0000
Subject: Counting the correct records.
Groups: php.db 
Request: Send a blank email to php-db+get-16082@lists.php.net to get a copy of this message
Howdy all, I hope you are well, I've run into a peculiar problem (PHP 4.0.6, PostgreSQL 7.1.3).. Table 1: EXPERTISE_FILE (ID (key), <data fields ...>) Table 2: DAMAGE_CASE (ID (key), OWNER_EXP_FILE (link to EXPERTISE_FILE), <data fields ...>) I am working on a script that mines these two tables to create customer statistics, so I SELECT a few fields from EXPERTISE_FILE and mostly do calculations on the DAMAGE_CASE fields (aggregate functions SUM, COUNT, etc..). In the WHERE clause I will specify exact values for the fields selected from EXPERTISE_FILE that I do not want to expand. Somewhere in the SELECT list there is also a COUNT(f.id) AS number. What this is =supposed= to do is count the number of EXPERTISE_FILE records that match the conditions, but it counts something else.. At first I thought it counted DAMAGE_CASE records, but that cannot be either. Number of EXPERTISE_FILE records: 6073 Number of DAMAGE_CASE records: 8251 If I manually add all the 'number' fields in the resultset, the total is 7629. I guess I'm missing something here. What does COUNT() actually count here? By the way, if I write COUNT(*) or COUNT(f.some_other_field) it will count the exact same. If anyone could clarify, I would most certainly be grateful. :) Thanks, (Please CC me in replies as I do not currently subscribe to this list (not at work, anyway)) -- Alexander Deruwe AQS-CarControl

« previous php.db (#16082) next »