This query works fine, but I am having trouble trying to figure out why it doesn’t return anything if the user has no categories in the user_categories table? This is the table structure:
users: user ID, username, user city
category: category id, category name
user_categories: user id, category id
SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories
FROM users
INNER JOIN user_categories ON users.user_id = user_categories.user_id
INNER JOIN categories ON user_categories.category_id = categories.category_id
WHERE users.user_city = 'brooklyn'
GROUP BY users.user_id
LIMIT 10
I just need the new “category” column to be empty if no rows exist for user_id in user_categories ...
Thank!
source
share