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 1102359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:10:28+00:00 2026-05-17T01:10:28+00:00

I have the following MySql Table: ——————————————– Table ‘category’ ——————————————– category_id name parent_id 1

  • 0

I have the following MySql Table:

--------------------------------------------
Table 'category'
--------------------------------------------
category_id    name        parent_id
1              animal      NULL
2              vegetable   NULL
3              mineral     NULL
4              dog         1
6              cat         1
7              carrot      2
8              quartz      3

The following SQL Statement will list all results like this:


category_id    category    sub_category
4              animal      dog
6              animal      cat
7              vegetable   carrot
8              mineral     quartz

SELECT sub_category.category_id AS category_id,
       category.name AS category,
       sub_category.name AS sub_category
FROM category
LEFT OUTER JOIN category AS sub_category
    ON sub_category.parent_id = category.category_id
WHERE category.parent_id IS NULL
ORDER BY category_id

But now I have another table with categories that particular users are NOT interested in:

--------------------------------------------
Table 'category_filter'
--------------------------------------------
user_id   category_id
1         4
1         7
1         8

How can I make a query for one particular user so that I get a list of all categories with an info whether a user is interested or not?

Something like this for example:

--------------------------------------------------------------
category_id    category    sub_category    interested
4              animal      dog             NULL
6              animal      cat             6
7              vegetable   carrot          7
8              mineral     quartz          NULL

Thanks in advance for your support.

  • 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-17T01:10:28+00:00Added an answer on May 17, 2026 at 1:10 am

    Use:

       SELECT c.category_id,
              c.name AS category,
              subc.name AS sub_category,
              cf.category_id AS interested
         FROM CATEGORY c
    LEFT JOIN CATEGORY subc ON subc.category_id = c.parent_id
                           AND subc.parent_id IS NULL
    LEFT JOIN CATEGORY_FILTER cf ON cf.category_id IN (c.category_id, subc.category_id)
                                AND cf.user_id = ?
        WHERE c.parent_id IS NOT NULL
    

    The join to CATEGORY_FILTER is different from @djacobson’s answer, in that it joins the table to both instances of the CATEGORY table.

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

Sidebar

Related Questions

I have a following mysql table with a lot (3000+) of values: [id] [parent_id]
I have the following mapping for my table in MySql: <class name=Tag, namespace table=tags
I have following mysql table: Item Name Listing Fee Listing Type watch $0.20 LISTED
I have the following MySQL table: | id | Name | Windows | Linux
I have the following mysql table: Products ID -- NAME -- INSTOCK -- REFERER
For example I have the following MySQL table: parent_id | child_id --------------------- 1 |
I have the following MySQL table structure: num field company phone website 1 Gas
I have the following table: mysql> SELECT * FROM `bright_promotion_earnings`; +----+----------+------------+----------+-------+ | id |
Lets say I have the following MySQL structure: CREATE TABLE `domains` ( `id` INT(10)
I have the following table in MySQL: ---------------------------- | id | price | price_promo

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.