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!
(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:
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: