Hi guys,
I have three tables which I am trying to join.
Metrics
metric_calculated_answers
metric_custom_report
The metric_custom_report table is the main one and all the results from that table will be shown (meeting the criteria)... I then need to look up in the metrics table for names of ID numbers stored in the custom_reports table.
I then would like to get get ALL the answers in the metric_calculated_answers table which meet the ID numbers in the custom_report table. the trouble is, the SQL I have used seems to repeat each row 4 times.
Is it possible or should I use two queries??
SELECT
m.*,
c.*
FROM metrics_custom_report c
LEFT JOIN metrics m
ON c.metricID = m.metricID
WHERE c.orgID='$orgID' AND
m.processID='$processID' AND
c.processID='$processID'
ORDER BY c.headline ASC, c.is_top_level DESC, c.hierarchy ASC
The above works nicely and gives me the data OK... when I try this though, thats when each row is replicated.
SELECT
m.*,
c.*,
mca.*
FROM metrics_custom_report c
LEFT JOIN metrics m
ON c.metricID = m.metricID
RIGHT JOIN metrics_calculated_answers mca
ON mca.metricID = c.metricID
WHERE c.orgID='$orgID' AND
m.processID='$processID' AND
c.processID='$processID' AND
mca.orgID='$orgID' AND mca.processID='$processID'
ORDER BY c.headline ASC, c.is_top_level DESC, c.hierarchy ASC
any help is much appreciated!!