# QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Action-Packed Learning Awaits! QlikWorld 2023. April 17 - 20 in Las Vegas: REGISTER NOW
cancel
Showing results for
Did you mean:
Contributor III

## Relationship between tables in Data Modelling

How to find the relationship between two table is one-to-one or one-many or many-to-many?

I have found below link but unable to understand, could someone explain in detail

data model relationships | Qlik Community

1 Solution

Accepted Solutions
Contributor III
Author

Hi Daniel,

Thank You for clear explanation.

4 Replies
Specialist
Contributor III
Author

hi  Ishtdeep,

I have already found this link but unable to understand. so looking for more information

Contributor III

Hello, suren946!

Suppose you have these two tables below:

Countries:

[ID, Country

1, EUA

2, Brazil

3, Japan

];

Cities:

[City, ID

Sao Paulo, 2

Tokyo, 3

New York, 1

];

The relationship between them is clearly one-to-one, but you can prove that by creating a third table with ID's from the first one and the count of occurrences of those ID's on the second table, like below:

IDsCount:

NoConcatenate

Resident Countries;

Left Join

Count(ID) As IDCount

Resident Cities

Group By ID;

Result:

As there is no record of IDCount greater than 1, we know the relationship between "Countries" and "Cities" tables is one-to-one.

Now, if we make this change to the second table:

Cities:

[City, ID

Sao Paulo, 2

San Diego, 1

Tokyo, 3

Rio de Janeiro, 2

New York, 1

];

And run script again, we end up with this result:

As now we have IDCount's greater than 1, the relationship between tables is one-to-many.

And from now, if we invert the search, counting the ID's from the second table on the first one, like this...

IDsCount:

NoConcatenate

Resident Cities;

Left Join

Count(ID) As IDCount

Resident Countries

Group By ID;

...and find IDCount's >1, we actually have many-to-many relationship tables.

Contributor III
Author

Hi Daniel,

Thank You for clear explanation.

Community Browser