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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:59:37+00:00 2026-05-18T23:59:37+00:00

I have two tables, table1 and table2. Table1 is in a one to many

  • 0

I have two tables, table1 and table2. Table1 is in a one to many relationship with table2 (one row in table1 maps to many rows in table2). There is a field in table2 called code. If none of the values of code in table2 equal some set of values (say 1, 2, and 3), I want to select the value in table1. I’m not sure how to write this kind of join.
Assume the primary key in table1 is called id and the foreign key to which it maps is called did. Can you tell me how to write this kind of join?

  • 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-18T23:59:37+00:00Added an answer on May 18, 2026 at 11:59 pm

    This is known as antijoin.

    The easiest implementation is:

    SELECT * FROM table1
    WHERE NOT EXISTS (SELECT 1 FROM table2
                      WHERE  table2.did = table1.id
                        AND  table2.code in (1,2,3))
    

    or, using outer join (I’m not 100% sure this will work, as I always use NOT EXIST syntax myself for antijoins):

    SELECT  table1.*
    FROM    table1
    LEFT OUTER JOIN
            table2
    ON      table1.id = table2.did
      AND  table2.code in (1,2,3)
    WHERE   table2.did is NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that have a one-to-many relationship table1 (one), table2 (many). table1
There are two tables, which have a relationship(one-to-many). There are Meals table which contains
I have two tables connected with one to many relationship. Parent Table is a
android noob... I have two tables, with a one to many relationship between country_tbl
I have two tables in a one to many relationship. (products and qty break
I have two tables: invoices & invoice_items. I need a one to many relationship
Let's say I have two tables with a one-to-many relationship. I want to create
I have two tables, that relate via a one-to-many relationship i.e tableOne (1)----------(*) tableTwo
I have two tables: invoice and charges, with a one-to-many relationship. (simplified) invoice has:
Suppose I have two tables in one to many relationship. And, I want to

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.