3 Table JOIN Question

wxdqz

New Member
Suppose I have 3 tables in MySQL DB:

1. widgets
2. access_log
3. comments

For every widget_id in the widgets table, there may be 0, 1 or more rows in the access_log and comments table. Of course, the rows in the access_log and comments table are not related.

How is possible to display widget_id, and a count of the widget_id from the access_log and comments table grouped by widget_id? I am able to do one JOIN ok:

SELECT widgets.widget_id, count(access_log.widget_id) FROM widgets LEFT JOIN access_log ON widgets.widget_id = access_log.widget_id GROUP BY widgets.widget_id

When I add an additional LEFT JOIN for the comments table as mentioned in the MySQL manual on JOINS, the resulting values don't match the actual values in the DB.

Is the solution to create a temporary table? Or is it possible to do this in one SQL query?

Thanks for any pointers,
Doug
 
Back
Top