I am writing a forum style log using MySQL as my databse
I have written the following query which worked successfully:
[SQL]
SELECT a.buildnumber, a.entered_by, a.date, b.Description as primdesc, c.Description as secdesc, a.notes, a.resolved as status FROM tbl_fault_log as a, tbl_primary_fault as b, tbl_secondary_fault as c where (a.primary_fault_id = b.id) and (a.secondary_fault_id = c.id) ORDER BY a.id ASC;
[/sql]
the table tbl_fault_log has a field history_id which links to tbl_history where all other history records for each record in tbl_fault_log are kept.
I want to amend the above query to include a count of history records in tbl_history for each record in tbl_fault_log.
I wrote this:
[sql]
SELECT a.buildnumber, a.entered_by, a.date, b.Description as primdesc, c.Description as secdesc, a.notes, a.resolved as status, a.history_id, count(DISTINCT d.id) as historycount FROM tbl_fault_log as a, tbl_primary_fault as b, tbl_secondary_fault as c,tbl_history as d where (a.primary_fault_id = b.id) and (a.secondary_fault_id = c.id) Group by a.buildnumber, a.entered_by, a.date, primdesc, secdesc, a.notes, status, a.history_id ORDER BY a.id ASC;
[/sql]
In my tbl_fault_log i have 2 dummy records setup to test functionality but there are no records as yet in tbl_history, there fore count(distinct d.id) should return 0.
However, with the new query (which doesnt throw any errors, warnings, fatals etc) i dont get any returned data whatsoever and no errors
Can anyone see where i am going wrong??
thanks in advance