OriyanJ OriyanJ - 1 year ago 83
SQL Question

Query that returns parent items with no children

I have a table that looks like this:

enter image description here

It has products. Some are related to a parent product by a "Parent ID".

I need a query that will only select parent products that don't have any children related to it. Such as "Product-4".

Can anyone help me with this? It seems quite an easy solution.

Answer Source
select NAME from my_table where ID not in (select parent_ID from my_table)

should do it

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download