Select from database not matching freepbx cdr report

I will keep this short.

FREEPBX produces the following from two CDR reports against one extension:
22 Inbound / 8 Outbound calls for specific date -> After I eliminate the duplicates from the CDR report, I have 11 Inbound / 8 Outbound.

So, I have to come up with a SQL statement that matches 11 Inbound / 8 Outbound for that user. A simplified version of the SQL statement reads:

FROM cdr, cel
WHERE cel.eventtype IN (‘CHAN_START’)
AND cdr.uniqueid = cel.uniqueid
AND cdr.calldate
AND cdr.cnum =
AND > 0

However, my results are 6 Inbound / 4 Outbound for the user.

So, the question is, what event types does FreePBX include in its SQL Statement and does it bother with using uniqueid in the query as they are not really unique.

Also, the database I am working with does not include a primary key for the CDR table, and there is no sequence field. I would like to avoid pulling back duplicate information, which FreePBX does on the Inbound.

Any assistance, suggestions, tips, etc would be much appreciated.


It looks like my query is missing calldate, cdr.cnum, and the list of fields after DISTINCT, but I assure you that they are there, just used brackets and that got omitted from my original post.