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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:27:01+00:00 2026-05-16T04:27:01+00:00

Maybe this way it will make more sense. MySQL table Code: id1 | id2

  • 0

Maybe this way it will make more sense.

MySQL “table”

Code:

id1 | id2
 1  |  2
 1  |  3
 2  |  4
 2  |  3
 3  |  4
 3  |  5

WHERE id1 = 1, this id is connected to 2 and 3: 1->2, 1->3

What I want to do is output the IDs of 2 and 3 which are NOT connected to 1, which in this particular case would be 4 and 5.

  • 2->4 (1 is NOT connected to 4 = OK)

  • 2->3 (1 is connected to 3 = NOT OK)

  • 3->4 (1 is NOT connected to 4 = OK) …but it should NOT be displayed twice, only because 2 and 3 are connected to 4!!

  • 3->5 (1 is NOT connected to 5 = OK)

The only thing I could come up with would looks similar to the OHO code below, but I’d want to do all this within just one simple MySQL query, if possible (i.e. JOIN?):

$a = mysql_query("SELECT id2 FROM table WHERE id1 = 1");
while($b = mysql_fetch_assoc($a))
{
    $c = mysql_query("SELECT id2 FROM table WHERE id1 = $b[id2]");
    while($d = mysql_fetch_assoc($c))
    {
        $e = mysql_query("SELECT id2 FROM table WHERE id1 = 1 AND id2 = $d[id2]");
        $f = mysql_fetch_assoc($e);
        if(!$f['id2'])
        {
            echo $f['id2'];
        }
    }
}

note: One problem with the PHP code above is it would output 4 twice, because 2 and 3 are both connected to 4.

  • 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-16T04:27:02+00:00Added an answer on May 16, 2026 at 4:27 am

    What about this?

    select distinct a.id2
    from myTable a
    join (select id1, id2 from myTable where id1 = 1) b on a.id1 = b.id2
    where NOT EXISTS (select 1 from myTable where id1 = b.id1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.