Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 633753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:13:13+00:00 2026-05-13T20:13:13+00:00

This query works fine but I’m having trouble trying to figure out why it

  • 0

This query works fine but I’m having trouble trying to figure out why it does not return anything if the user does not have any categories in the table “user_categories”? This is the table structure:

users: user id, username, user city

categories: 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 for the new column “categories” to be empty if no rows existed for the user_id in user_categories…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T20:13:14+00:00Added an answer on May 13, 2026 at 8:13 pm

    You are using the wrong type of join – inner join will only succeed if a match is found in both tables. Instead, you want to try an outer join. Try something like this:

    SELECT users.*, GROUP_CONCAT(categories.category_name) AS categories
    FROM users
    LEFT OUTER JOIN user_categories ON users.user_id = user_categories.user_id
    LEFT OUTER JOIN categories ON user_categories.category_id = categories.category_id
    WHERE users.user_city = 'brooklyn'
    GROUP BY users.user_id
    LIMIT 10
    

    The Wikipedia SQL JOIN article is a pretty decent summary of the join types available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to group table values by date, and this HQL query works fine:
I am having trouble with this query but ONLY under HSQLDB. We use Oracle
This query works fine, but there seems to be an error in the definitions
When I run this query, it works fine but the individual fields would pull
I want to port this SQL query, which works just fine on SQL Server,
This has to be obtained from a remote machine. The following query works not
I'm having this Mysql query, It works: SELECT nom ,prenom ,(SELECT GROUP_CONCAT(category_en) FROM (SELECT
I'm logging output with log = /var/log/mysql/query.log and this works ok, but I only
In SQL SERVER 2005 This query works fine : Select * from sys.procedures where
I tested this query in my database, and it works fine: select * from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.