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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:02:49+00:00 2026-05-25T10:02:49+00:00

This is kind of difficult to describe. I have a table with two fields:

  • 0

This is kind of difficult to describe. I have a table with two fields: Col1, Col2 with the following data:

Col1, Col2
  1    10
  1    11
  1    12
  10   1
  11   1
  13   1

The values in Col1 can act like a foreign key value in Col2. I want to find all the rows for a given value in Col1 where the value in Col2 appears in Col1 but where it’s Col2 value is also the given value. So for example, if I am looking for the value of 1 in Col1, the following rows are returned:

Col1, Col2
  1    10
  1    11
  10   1
  11   1

The row with Col1 set to 13 would not be returned because it does not appear in Col2 where Col1 is set to 1.

The sql I created works:

Select T1.*
From Table1 T1
Inner Join Table1 T2 On T1.Col2 = T2.Col1
Where (Exists(Select * From Table1 T3 Where (T2.Col1 = T3.Col1) And (T3.Col2 = T1.Col1)))
And (T1.Col1 = 1)

This returns duplicates of rows. I can always add the DISTINCT keyword and this will remove the duplicates. My question is whether my sql is really the correct way of selecting the records and whether it can be done without the DISTINCT keyword.

  • 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-25T10:02:50+00:00Added an answer on May 25, 2026 at 10:02 am

    I think this may do what you want:

    SELECT T1.*
    FROM Table1 T1
    JOIN Table1 T2 ON (T1.Col2 = T2.Col1) AND (T1.Col1 = T2.Col2)
    WHERE T1.Col1 = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a kind of difficult one to explain but basically I have a
I'm sorry if this was already answered, but it's kind of difficult to search
this kind of emergency, so please, can someone help me... I'm using movingboxes plugin
I know this kind of questions have been asked already many times before. The
I am sure that this kind of questions must have been asked before, but
I have this kind of node in my xml document: <parent ...> <a .../>
This is kind of a hard question to describe, and I've searched for about
This is kind of difficult to explain so ill link to a page that
This is kind of difficult to explain, so I'll paste the function, and explain
It's very difficult to find this kind of document online. I found one in

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.