How do I join these queries?

Posted by GregoryD on Stack Overflow See other posts from Stack Overflow or by GregoryD
Published on 2010-04-08T16:36:53Z Indexed on 2010/04/08 16:43 UTC
Read the original article Hit count: 834

Filed under:
|
|
|

query1:

SELECT category.id, category.name, category.level, category.description, category.cat1, category.cat2, category.cat3, category.cat4, category.pri_color, category.sec_color, category.last_report AS report_id FROM category, reports_category_layout WHERE category.id = reports_category_layout.catID AND reports_category_layout.site_code = 'las'

query2:

SELECT DISTINCT category.id, COUNT(forum.id) AS posts, SUM(forum.view) AS views FROM category, forum WHERE category.id = forum.catID AND forum.approved = 'yes' AND forum.site_code = 'las' GROUP BY category.id

query3:

SELECT forum.catID, forum.title, forum.paragraph, forum.created, users.alias, forum.userID FROM forum, users, forum_cache WHERE forum.catID = forum_cache.catID AND forum.id = forum_cache.last_report AND users.id = forum.userID AND forum.approved = 'yes'

Essentially, I am unsure about the syntax to join these properly. I have written a query that simply joins them, but in the case that the forum cache table contains an unapproved forum id, it will simply not return the entire row.

what I really need is for query1 and query2 to be left joined on the category id, and for query 3 to be left outer joined on id = catID.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about left