Hi guys, I've got a problem that's driving me nuts and have no idea of what's going on.
Essentially I've got a query which in the select clause includes a sub query which gets customer_ids with the earliest associated datetime, this is because each customer can have several entries and I am required to do some analysis on the data from the earliest entry for each one only.
So I do the subquery in select like: (select customer_id as custid, min(thetime) as custtime from thetable) as info ....
then in the WHERE clause I do:
WHERE table.customer_id = info.custid and table.thetime = info.custtime
I've run the subquery on it's own and it works as expected returning 11 rows out of a possible 16 (it's removed later duplicates). The main query also does it's job and returns all 16 (without the subquery check). If I put the WHERE clause in and join the two I only get 8 rows back!
I've checked the results of the two queries against each other and in the 16 from the main query are the 11 the sub query returns, they appear to be identical so I have no idea where they're going. If I change the where clause and just "where table.thetime in (info.custtime)" I seem to get 9 results :S
Is there some change in the data format between the table and the subquery results? Both queries operate on the same table, I really can't see where this is losing the other 3 rows.
Essentially I've got a query which in the select clause includes a sub query which gets customer_ids with the earliest associated datetime, this is because each customer can have several entries and I am required to do some analysis on the data from the earliest entry for each one only.
So I do the subquery in select like: (select customer_id as custid, min(thetime) as custtime from thetable) as info ....
then in the WHERE clause I do:
WHERE table.customer_id = info.custid and table.thetime = info.custtime
I've run the subquery on it's own and it works as expected returning 11 rows out of a possible 16 (it's removed later duplicates). The main query also does it's job and returns all 16 (without the subquery check). If I put the WHERE clause in and join the two I only get 8 rows back!
I've checked the results of the two queries against each other and in the 16 from the main query are the 11 the sub query returns, they appear to be identical so I have no idea where they're going. If I change the where clause and just "where table.thetime in (info.custtime)" I seem to get 9 results :S
Is there some change in the data format between the table and the subquery results? Both queries operate on the same table, I really can't see where this is losing the other 3 rows.