Select Rows Where Value from One Column Matches Other Column

TL;DR: Use a JOIN.

I’ve got a table representing a tree, using two columns:

and I want to select all children for parents whose CLASS_ID have a certain value (e.g. abcd).

The way I could do it was via a JOIN statement:

This will:

  • Perform a join where child.parent_prop_id = parent.prop_id
  • Filter only parent.class_id = 'abcd'

Simple.

Bonus

This will work with other databases as well :)

HTH,


A little experiment: If you find this post and ad below useful, please check the ad out :-)




Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top