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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:59:33+00:00 2026-06-18T03:59:33+00:00

Consider that I have two tables. One is Table1 as shown below. One more

  • 0

Consider that I have two tables.

One is “Table1” as shown below.

enter image description here

One more table is “Table2” as shown below.

enter image description here

Now here what I need is, I need all the records from Table1 those ID’s are not in Table2’s Reference column.

Please guide me how to do this.

Thanks 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-18T03:59:34+00:00Added an answer on June 18, 2026 at 3:59 am

    How to do it with your current schema (impossible to use indexes):

    SELECT Table1.*
    FROM Table1
    WHERE NOT EXISTS
    (
        SELECT 1
        FROM Table2
        WHERE CONCAT(',', Table2.Reference, ',') LIKE CONCAT('%,', Table1.ID, ',%')
    )
    

    How this works is by completely wrapping every value in the Reference column with commas. You will end up with ,2,3, and ,7,8,9, for your sample data. Then you can safely search for ,<Table1.ID>, within that string.


    How to really do it:

    Normalize your database, and get rid of those ugly, useless comma-separated lists.

    Fix your table2 to be:

     SlNo | Reference
    ------+-----------
        1 |        2
        1 |        3
        2 |        7
        2 |        8
        2 |        9
    

    and add a table2Names as:

     SlNo | Name
    ------+---------
        1 | Test
        2 | Test 2
    

    Then you can simply do:

    SELECT Table1.*
    FROM Table1
    WHERE NOT EXISTS(SELECT 1 FROM Table2 WHERE Table2.Reference = Table1.ID)
    
    • 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 relate via a one-to-many relationship i.e tableOne (1)----------(*) tableTwo
RDBMS SQL Server, T-SQL Consider a table that links information from two different tables:
Consider the following scenario We have a simple database that involves two entities: user
Consider a situation. I have an in-proc COM server that contains two COM classes.
Consider that I have 1 resource and 2 urls (let's say new one and
Consider following two tables: tag_names (tag_id, tag_name) tag_links (tag_id, image_id) An image can have
Not sure why I can't figure this one out. Basically, I have two tables
Let's say we have a field that can be in more than one type,
Consider the following: I have two tables (Customers and Cases) defined as follows: **Customers**
Consider I have two database tables: images and albums . They have these schemas:

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.