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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:05:42+00:00 2026-06-13T23:05:42+00:00

I have the following Tables: Table A id | name 1 | foo 2

  • 0

I have the following Tables:

Table A
id | name
1  | foo
2  | bar

Table B
id | name | default
1  | 123  | 1
2  | 321  | 0
3  | 456  | 1

Table C
A_id | B_id
1    | 2
1    | 3

now I would like to get the A-B pairs (with condition that these pairs have B.default = 1) which are not in C

So the expected result would be:

A_id | B_id
1    | 1
2    | 1
2    | 3

but I’m totally confused about how to join table B in:

SELECT A.id, B.id
FROM A

LEFT OUTER JOIN C
ON C.A_id = A.id

LEFT OUTER JOIN B
AND C.B_id = B.id
AND B.default = 1
  • 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-13T23:05:42+00:00Added an answer on June 13, 2026 at 11:05 pm

    Generate all A-pairs first, then compare to C

    The NOT EXISTS is slightly more correct (anti-semi-join) than a LEFT JOIN

    SELECT
        X.A_id, X.B_id
    FROM
        (
        SELECT
          A.id AS A_id,
          B.id AS B_id
        FROM
          A CROSS JOIN B
        WHERE
          B.default = 1
        ) X
    WHERE
       NOT EXISTS (SELECT *
          FROM
             C
          WHERE
             C.A_id = X.A_id
             AND
             C.B_id = X.B_id)
    

    However, this gives this result. Only the C tuple of (1,3) matches the 4 A-B pairs

    A_id | B_id
    1    | 1
    2    | 1
    2    | 3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the folowing tables: Table student: id name 1 foo 2 bar 3
I have the following two tables in my mysql database. Table Name: groups id
Imagine I have following table: NAME DATE OTHER_CONTANT 'A' '2012-06-05' 'baz' 'A' '2012-06-04' 'bar'
I have the following tables: Item (Table) no name price description Item-custom (Table) userid
Assume I have the following tables: TABLE: foo - foo_id (PK) TABLE: tag -
Assume the following tables: TABLE: foo ========================= | foo_id | fk_id | name |
I have two 2 tables in my database Table: Foo Table: Bar ----------------- ---------------------
I have the following two tables: Table1 ---------- ID Name 1 A 2 B
I have the following table drop table names; create table names( name varchar(200), surname
I have a following table ------------ id name ------------ 1 master 2 datagrid 3

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.