Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading