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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:07:14+00:00 2026-05-26T10:07:14+00:00

I have 2 tables Table_A and Table_B. Table_A is a parent of Table_B. Table_B

  • 0

I have 2 tables Table_A and Table_B. Table_A is a parent of Table_B. Table_B has 2 columns which refer to Table_A(I Mean both the columns refer to a column in Parent).

Table_A contains following columns (id,name,className)
Table_B contains following column (source,destination) both the columns refer to id in Table_A

Assume that Table_A contains the following data

id     name    className 
---------------------------
1       N1      C1 
2       N2      C2
3       N3      C3
4       N4      C4
5       N5      C6

Table_B

Source  Destination
------------------
1        2
2        3
3        4
3        5

I need a query where I require all Ids present in the Destination and not in Source and I need to join this Ids with Table_A to get name and className.

For the data I have shown the query should retrieve the following rows.

4     N4   C4
5     N5   C5

BTW here I have shown partial data but Table_B has more than 1000 records.

EDIT

I have written the following query but it was showing wrong results

select * from Table_A where id not in (select distinct Source from Table_B)

But it was giving right results currently but on long run we may face performance issue and also query retrieves data which is not present in both Source and Destination.

  • 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-26T10:07:15+00:00Added an answer on May 26, 2026 at 10:07 am

    I only have SQLite installed, but this short query did the job:

    SELECT table1.id, table1.name
    FROM table1, table2
    WHERE table2.destination NOT IN
            (SELECT DISTINCT source FROM table2)
    AND table1.id=table2.destination;
    
    -- Result:
    -- 4|N4
    -- 5|N5
    

    EDIT: Of course it would be interesting to see a performance comparison with other solutions.

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

Sidebar

Related Questions

I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.
i have 3 tables A,B and C. table A has column employee_name,id table B
How can I search for in table_a table_b table_c , which have a random
I have a table y Which has two columns a and b Entries are:
I have a table dbo.comp has id and name as columns. dbo.comp Name id
I have a CMS system which has a sitemap table with a parent-child relationship
I currently have a table which has these columns: id (INT) parent_id (INT) col0
I have 2 tables, one parent TableA and one child TableB. TableB has 1
I have a table with the following structure ID Name Parent ----------- -------------------------------------------------- -----------
I have two tables, for example: Table A Table B ======= ======= 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.