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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:41:55+00:00 2026-06-18T23:41:55+00:00

Class ClassId (PK) ClassName ClassCapacity Batch BatchId (PK) BatchName Size Status {NotStarted, Enrolled, Completed}

  • 0

Class

  • ClassId (PK)
  • ClassName
  • ClassCapacity

Batch

  • BatchId (PK)
  • BatchName
  • Size
  • Status {NotStarted, Enrolled, Completed}

BatchClass

  • BatchClassId (PK)
  • BatchId (FK)
  • ClassId (FK)
  • NoOfStudents

Relationship

  • A class has maximum capacity, therefore a batch can have many classes, but at a given time a class can be allocated only for one batch that status is = Enrolled (This is to be validated from the application end)

I want to get all the classes that are not currently allocated to a batch that status is not equal to Enrolled

This is what I tried,

SELECT C.* 
FROM Class C 
LEFT JOIN (
    Batch B 
      INNER JOIN BatchClass BC 
        ON B.BatchId = BC.BatchId
    ) ON C.ClassId = BC.ClassId 
WHERE B.Status <> "Enrolled";

Even though when I try WHERE B.Status = “Enrolled” it gives all the classes that have a enrolled batch. What I want is the Opposite which didn’t work for me from above SQL.

I’m not sure is it something wrong in my design or SQL statement. Please help. Thank you in advance.

  • 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-06-18T23:41:56+00:00Added an answer on June 18, 2026 at 11:41 pm

    This should work fine:

    SELECT DISTINCT C.* 
    FROM Class AS C 
    INNER JOIN BatchClass AS BC ON C.ClassID = BC.ClassID
    INNER JOIN Batch      AS B  ON B.BatchId = BC.BatchId 
    WHERE B.Status <> 'Enrolled';
    

    SQL Fiddle Demo


    Update 1

    Try this instead:

    SELECT C.*
    FROM Class AS C 
    WHERE c.ClassID NOT IN(SELECT bc.ClassID
                           FROM BatchClass bc
                           INNER JOIN Batch b ON B.BatchId = BC.BatchId
                           WHERE b.status = 'Enrolled');
    

    Updated SQL Fiddle Demo

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

Sidebar

Related Questions

public class Atribut { int classid; @Override public String toString() { return Integer.toString(classid); }
SELECT a.ClassName, b.TeacherName, COUNT(c.Class_ID) from dbo.Class a inner join dbo.Teacher b on a.Teacher_ID =
i need to know how can detect if an OCX class (ClassID) is registred
I have an Entity like this: public class Category { public int classid {get;set;}
I have the following method in my UIButton class: - (id)initWithCoder:(NSCoder *)aDecoder{ self =
I have a structure of base class and a couple of inherited classed. Base
I understand that CoCreateInstance finds the COM server for the given class id, creates
So, classic simple Singleton realization is following: class Singleton { private: static Singleton* singleton;
I have this code below. I need to use a class id instead of
class Widget; std::vector< std::shared_ptr<Widget> > container class Criterium { public: bool operator()(const Widget& left,

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.