Wednesday, 21 August 2013

SQL Count goes crazy when joined

SQL Count goes crazy when joined

So i have the following SQL statement:
SELECT COUNT("Oprettet af Initialer") AS meetings_booked
FROM KS_DRIFT.DIAN_POT_OPR
WHERE "Oprettet dato" = '2013-08-12'
AND "Oprettet af Initialer" = 'JOEB'
Now this returns the right number (71)
Now this was just a test i have to do the same for the whole table but
only include some where Oprettet af Initialer is equal to the row
Initialer in another table.
For this i decided to use a join:
SELECT COUNT("Oprettet af Initialer") AS meetings_booked
FROM KS_DRIFT.DIAN_POT_OPR INNER JOIN KS_DRIFT.V_TEAM_DATO ON
KS_DRIFT.DIAN_POT_OPR."Oprettet af Initialer" =
KS_DRIFT.V_TEAM_DATO.INITIALER
WHERE "Oprettet dato" = '2013-08-12'
AND "Oprettet af Initialer" = 'JOEB'
How ever when i run this i get the following output:181476.
Which is clearly a mistake!
Now i have a gut feeling telling me that it is counting everything from
both rows however i have no idea how to fix it?

No comments:

Post a Comment