How to get all tuples related to one passed by parameter in SQL?

enter image description here

Using this hipotetical scenario (image above), what is the best way to show the name of the Children related to the Parents’ ID passed by parameter?

For example: if I receive 1 as Parents’ parameter, I need to show the name for their children. In this case? Emily, Alexander and Sophia
if I receive 7 as Parents’ parameter, I need to show the Children’s name: Olivia and James.

>Solution :

Basic SQL:

SELECT b.name
FROM   a
JOIN   b ON b.id = a.children
WHERE  a.parents = 1;

You have rather unwieldy column names.

Leave a Reply