# Parent / Child Related Lists

## 📚 What are parent / child related lists ?

Thanks to the dynamic piping features you may  create cascading lists that are generated dynamically based on other lists selections.

In this example we will suppose that we already have a table of companies and employees and take a list of those companies and a list of their employees to show how to link both to create a dynamic parent / child related list.

![](https://1025048312-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8fLhS0bmfBRyq0HdUm%2F-MC0YVUop8Vp6Eo87MYP%2F-MC0Ze1epTnIjTqc_pYn%2Fimage.png?alt=media\&token=9ce3bfec-2e74-4af9-875e-5b9641f09255)

## 1. The company SQL answer type

First things first we need to [create](https://docs.ngsurvey.com/form-management/form-designer/answers/answer-types/creating-new-type) a new [SQL Answer type](https://docs.ngsurvey.com/form-management/form-designer/answers/answer-types/creating-new-type/lists/sql-server-lists) for the companies list that will get all companies from the database and their ids.

```sql
SELECT Id, Name FROM Company
```

Now that we have our company list we can [add](https://docs.ngsurvey.com/form-management/form-designer/answers/create-answers) this newly created answer type to any questions or our survey. Once its added open its [answer properties](https://docs.ngsurvey.com/form-management/form-designer/answers/answer-properties) and set its pipe alias property to : CompanyId

![](https://1025048312-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M8fLhS0bmfBRyq0HdUm%2F-MC0_lnEFeJRySakrBnr%2F-MC0_zhk-ynUcykBUwSi%2Fimage.png?alt=media\&token=19ea4140-3c57-463e-93c3-cbb6270d0d5a)

## 2. The employee SQL answer type

We have now to create our employee answer sql answer item that will be linked to the companies. To do that create a new answer sql type with following query

```sql
SELECT Id, Name FROM Employee WHERE CompanyId = @CompanyId
```

Add a new [SQL parameter](https://docs.ngsurvey.com/form-management/form-designer/answers/answer-types/creating-new-type/lists/sql-server-lists/sql-parameters) to your [SQL answer type](https://docs.ngsurvey.com/form-management/form-designer/answers/answer-types/creating-new-type/lists/sql-server-lists) with following parameters

* **name** CompanyId, \
  **value**: \[\[CompanyId]]

Next [add ](https://docs.ngsurvey.com/form-management/form-designer/answers/create-answers)that employee SQL list answer type to any of your survey question. \
\
ngSurvey will during the survey lookup the answer having a [pipe alias](https://docs.ngsurvey.com/form-management/form-designer/piping/text-data-piping) set to CompanyId and use the  value entered / chosen by the respondent as a parameter for the employee query. In our example it will retrieve all the employee of the selected company of the other sql list.

If you only want to show the list when there is an actual result you can enable the Hide on empty query results which will hide the list as long as the respondent did not select any value in the company list.

There are no limits on the number of lists that can be inter-connected and you can as well connect any other ngSurvey answer type that support value piping to your list
