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 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

Ask A Question

Stats

  • Questions 510k
  • Answers 510k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use structs to wrap up an array. This… May 16, 2026 at 5:03 pm
  • Editorial Team
    Editorial Team added an answer You get an error because it is not allowed to… May 16, 2026 at 5:03 pm
  • Editorial Team
    Editorial Team added an answer There is a confusion with the instructions you're following. The… May 16, 2026 at 5:03 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I want to make chain-calling like jquery-way in c++. The sample: $('#obj').getParent().remove(); So, as
Is there a way to use Haskell's map or something similar with multiple arguments?
I ran Perl::Critic on one of my scripts, and got this message: Regular expression
Let's say that I'm currently designing an application where I will need to use
My question is best illustrated with a code sample, so let's just start off
i want to generate a sequence of unique random numbers in the range of
I have been tasked with designing an ecommerce solution. The aspect that is causing
I'm writing an application that is basically just a preferences dialog, much like the
For example, I have a document library that hold contracts for multiple projects. So:
intro Hello, I'm trying to develop some plugin or / and object in javascript,

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.