I have four tables
post
-------------
post_id
cat_id
posts
post_category
-------------
cat_id
cat_name
users
-------------
user_id
user_name
user_category_map
-------------
user_id
cat_id
I want all posts added by all users in all post categories
I have written this query
SELECT posts
FROM post p, users u, user_category_map ucm
WHERE p.cat_id = ucm.cat_id
AND ucm.user_id = u.user_id
but I am getting repeated posts. Is my table structure correct and normalized properly. I am not able to correctly grab the logic. Is the join I put is correct?
The design does not look correct. Instead of a reference table for user_category, you should have a reference table for user_post. In current scenario, if same user adds multiple posts for same category, you will end up having duplicate rows in user_category_map