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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:05:22+00:00 2026-05-27T08:05:22+00:00

i have a main table categories like this categories_id | categories_status | parent_id 1

  • 0

i have a main table categories like this

categories_id | categories_status | parent_id
     1                  1               0
     2                  1               0
     3                  1               1
     4                  1               2
     5                  1               1
     6                  1               2

and a reference table products_to_categories

categories_id | products_id
      3             778
      3             998
      5             666
      5             744

I select all the categories with no child-category:

SELECT * FROM categories
WHERE categories_id not in ( SELECT parent_id FROM categories )
# gets entries with id 3, 4, 5, 6

and no products in reference table:

AND categories_id NOT IN ( SELECT categories_id FROM products_to_categories )
# gets entries with id 4, 6

Now i would like to update the categories_status for this result but it don’t work just changing SELECT to UPDATE:

UPDATE categories
SET categories_status = 0
WHERE categories_id not in ( SELECT parent_id FROM categories )
AND categories_id NOT IN ( SELECT categories_id FROM products_to_categories )

There a few similar questions, but i can’t figure out how to change my example…

Thanks & best regards,

Alex

  • 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-27T08:05:23+00:00Added an answer on May 27, 2026 at 8:05 am

    Instead of sub-queries, use a left outer join

    update 
    categories c1
    left outer join categories c2 on c1.ID = c2.Parent_id
    left outer join products_to_categories p on c1.categories_id = p.categories_id
    set c1.categories_status = 0
    where c2.ID is null and p.categories_id is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table with hierarchical structure. like this: (source: aspalliance.com ) and table
I have a main category and some sub-categories for this category and I wanted
I have main table called 'Employee' and another slave table called 'EmployeeTypes' that has
I have a main table that I must get data from. I have a
I have a main Table, with several child tables. TableA and TableAChild1 and TableAChild2.
i have a table called category in which i have main category ids and
I have a structure where the main table is USER, other tables include CATEGORY
I have following situation. A main table and many other tables linked together with
I have 3 tables I need to join. The contracts table is the main
NHibernatians! I have a table [dbo].[Wibble] and another table [dbo].[WibbleExtended]. [Wibble] is the main

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.