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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:25:08+00:00 2026-05-27T05:25:08+00:00

I have a (legacy) table that has columns in it: bug_num build_id closed_to 1

  • 0

I have a (legacy) table that has columns in it:

bug_num   build_id    closed_to
1         3            NULL
2         4            NULL
3         NULL         1
4         3            NULL
5         NULL         2

I want to write a query where it will select all bugs from a specific build, and all bugs that were closed to a bug in that build. So, if I wanted to do it for build 3, it would include #s 1 and 4 (since they’re in build 3) and also 3, since it was closed to a bug in build 3 (1).

I thought I was close with:

SELECT stat.bug_num, 
       stat.build_id 
FROM   bug_status stat 
       JOIN bug_status stat2 
         ON stat2.closed_to = stat.bug_num 
WHERE  stat.build_id = 3; 

…but it doesn’t seem to be giving me the desired result. Thanks for your help!

  • 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-27T05:25:08+00:00Added an answer on May 27, 2026 at 5:25 am
    SELECT stat.bug_num,
           stat.build_id
      FROM bug_status  stat
     WHERE stat.build_id = 3
        OR stat.closed_to IN
            ( SELECT stat2.bug_num
                FROM bug_status  stat2
               WHERE stat2.build_id = 3
            )
    ;
    

    (It’s also possible to do this with a JOIN, or with a JOIN and a UNION, but I believe the above is the most intuitive way.)


    Edited to add: Here is a MySQL transcript demonstrating the above:

    mysql> create table bug_status
        -> (bug_num numeric, build_id numeric, closed_to numeric);
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> insert into bug_status values (1, 3, null);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into bug_status values (2, 4, null);
    Query OK, 1 row affected (0.01 sec)
    
    mysql> insert into bug_status values (3, null, 1);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into bug_status values (4, 3, null);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> insert into bug_status values (5, null, 2);
    Query OK, 1 row affected (0.00 sec)
    
    mysql> SELECT stat.bug_num,
        ->        stat.build_id
        ->   FROM bug_status  stat
        ->  WHERE stat.build_id = 3
        ->     OR stat.closed_to IN
        ->         ( SELECT stat2.bug_num
        ->             FROM bug_status  stat2
        ->            WHERE stat2.build_id = 3
        ->         )
        -> ;
    +---------+----------+
    | bug_num | build_id |
    +---------+----------+
    |       1 |        3 |
    |       3 |     NULL |
    |       4 |        3 |
    +---------+----------+
    3 rows in set (0.00 sec)
    

    Edited to add, since the IN (...) approach doesn’t seem to work in the OP’s version of MySQL: Here is an alternative query that gives the same result:

    SELECT stat.bug_num,
           stat.build_id
      FROM bug_status  stat
      LEFT
     OUTER
      JOIN bug_status  stat2
        ON stat.closed_to = stat2.bug_num
     WHERE stat.build_id = 3
        OR stat2.build_id = 3
    ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy table that has as a part of its natural key
I have a table that has old, legacy data along with new data. The
I have a legacy object model that has content objects and a table designed
I have a legacy MS Access 2007 table that contains 52 fields (1 field
I have a legacy MySQL table called lnk_lists_addresses with columns list_id and address_id .
I have a table which has essentially boolean values in a legacy database. The
I have a legacy table with about 100 columns (90% nullable). In those 90
I am trying to integrate with a Legacy table that has a column named
I want to access a legacy database schema from Rails. I have one table
Edit: using SQL Server 2005. I have a query that has to check whether

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.