MySQL Correlated Subquery Best Practices

I've been getting around this type of issue with script instead of handling it with the initial query, and I was wondering how best to approach it from a SQL perspective.
Using this table as an example,
ExampleHow would I design a query to select any ticket names that are like ('Replace PCs%' and IS_PARENT='1') as well as any ticket that has the PARENT_ID of the previously selected tickets? So, basically, how do I return an array containing both parent and children tickets related to a specific ticket name pattern? I would need the array to hold all fields related to the selected records. Thanks for reading.
thedeal56Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
Here is an approach, but MySQL is quite limited in its capabilities for hierarchical data. The following assumes just a 2 tier hierarchy as depicted.
select
      *
from tickets
where is_parent = 1
and ticket_name  like 'Replace PCs%'

union all

select
      c.*
from tickets c
inner join (
            select
                 id
            from tickets
            where is_parent = 1
            and ticket_name  like 'Replace PCs%'
           ) p on c.parent_id = p.id
;

Open in new window

see http://sqlfiddle.com/#!9/f8671/5

{+ edit}  small note: providing sample data in a re-usable way is appreciated (not images)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thedeal56Author Commented:
Thank you so much.  That helps a lot.  Sorry for the static image.
0
PortletPaulfreelancerCommented:
no problem, it wasn't too much typing, keep it in mind next time
(using an embedded image is better than an attached image as we don't have to flip between pages)

thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.