Hi i need help with a query.
I have 4 tables
articles - id, category_id, user_id
categories - id
article_category - article_id, category_id
users - id
The category_id in the article table is used determine the main category
Now I want to get all articles so i uses the query below.
Article can have more than one category. I want to see a list of articles with the main category information attached
SELECT a.*, c.title , c.slug
FROM articles a, article_category ac, categories c, users u
WHERE ac.article_id = a.category_id is supposed to be ac.article_id = a.id
AND ac.category_id = c.id
AND a.user_id = u.id
AND ac.category_id = '1'
Problem with this query is that i get the incorrect category information and i dont think i should run a subquery like the one below to solve it
(select title from categories where id = a.category_id) as title
Thanks