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

  • Home
  • SEARCH
  • 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 6012071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:21:04+00:00 2026-05-23T02:21:04+00:00

i have a Relation from N to N from categories to Items in my

  • 0

i have a Relation from N to N from categories to Items in my database.

I have three tables for this:

Categories, Items and Categories_Items

I would like to get all the categories and an extra field beside each one telling me if is active or not.

This is what i have by the moment:

SELECT    C.ID
          ,C.Name
          ,IsActive=????
      FROM Categories C
      left join Items_Categories IC on IC.CategoryID=C.ID
  where IC.ItemId=@ItemID

The result i would like to get is a list of all the available categories and marked as active those that are in the table Items_Categories and matches with the @ItemId:

ID  Name      IsActive
-- ---------  --------
1  Category1  0
2  Category2  1
3  Category3  .....
  • 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-23T02:21:05+00:00Added an answer on May 23, 2026 at 2:21 am

    Try this:

    SELECT  C.ID
                    ,C.Name
                    ,CASE 
                        WHEN IC.CategoryID IS NULL THEN 0
                        ELSE 1
                    END IsActive
        FROM    Categories C LEFT JOIN Items_Categories IC 
            ON IC.CategoryID=C.ID
        AND IC.ItemId=@ItemID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Cinema table & City table and I have relation with this tables
Hi I have a Linq CodeBehind Function Like this var result = from m
I have data with no relation. Just need to count various columns from 3
I have two tables, Products and BundleProducts that have o2o relation with BaseProducts. A
I have two tables with relation: modelBuilder.Entity<User>() .HasOptional(u => u.Subscription) .WithMany(); how can I
In relation to this question ( Efficient hashCode() implementation ) I have one more
I have this problem decomposing a relation schema into a set of schemas that
I have to delete rows from guide_category that have no relation with guide table
I have a database with 3 relations Offers, Products & Categories. I'm trying to
I have problem with mapping existing database. 2 tables (simplified) SomeEntity Id int Name

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.