# Table Relationships

You can connect separate tables via their shared dimensions using Dimension Relationship on Presight.

For example, in the Invoice table, each invoice line has a Customer ID, showing who is buying the products. Then, you will need to see all information about that customer: name, location, age... for further analysis, and the information belongs to Customer table. You will need **join two Tables via dimension Customer ID**

## 1. Joining tables to make Relationships via Data Relationship

You can create relationship via table view at <mark style="color:blue;">**Data Hub**</mark>**,** tab <mark style="color:purple;">**Data Relationship:**</mark>

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FhGLg6fgtp4fi4FaC48NL%2Fimage.png?alt=media&#x26;token=1918959d-fbdb-41b9-87c6-2aa88ed85ad8" alt="" width="563"><figcaption></figcaption></figure>

You can just ***click, drag*** and ***drop*** at the column from one table to another column at another table to create relationship, then, a pop-up will appear for you to choose Relationship Type:

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2Fmlet5Lo0DoQNYMOkjPkM%2Frela.gif?alt=media&#x26;token=50040ecb-e2ce-48df-af2e-5232d7794e6f" alt="" width="563"><figcaption></figcaption></figure>

Choose the **`Relationship Type`**:

* **Belongs to** (Many to 1): when many records from Table A belong to one single record in Table B.
* **Has Many** (1 to Many): when one single record from Table A has many records in Table B.
* **Has One** (1 to 1): when one single record from Table A has only one record in Table B.

### Editing Relationships at the Data Diagram

You can also edit or delete relationships on the Data Diagram, by clicking on the relationship arrow and choose to <mark style="color:blue;">**View/ Edit Relationship**</mark> or to <mark style="color:red;">**Remove Relationship**</mark>:

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2F3ULM8KD51tI1RqNDTKW7%2Fimage.png?alt=media&#x26;token=0747e973-1a69-4b16-900d-87974bc4d352" alt=""><figcaption></figcaption></figure>

## 2. Creating Relationships by editing a dimension

* Find the **Dimension** you want to add a relationship and click **`Edit`**:

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FNTAjbkTteQNA0AgWZtC3%2Fimage.png?alt=media&#x26;token=0ea9b4d6-0353-4599-bb1f-8f1af42e2dc7" alt=""><figcaption></figcaption></figure>

* Move to the tab <mark style="color:blue;">**Relationship**</mark>, and choose **`Edit Relationship`**

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FBIrwHPpBIZT5XP8rcJ0A%2Fimage.png?alt=media&#x26;token=f10517a8-ddbf-4594-9ce4-68ca94915b32" alt=""><figcaption></figcaption></figure>

* A box **`Add Another Relationship`** will appear and allows to add relationship.

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FUnwzb2wEABXyiNoINJZT%2Fimage.png?alt=media&#x26;token=aaad07e7-028c-49c3-9891-1ec1cd891a5a" alt=""><figcaption></figcaption></figure>

* Choose the correspondent dimension from another table. In this case, dimension <mark style="color:blue;">**Customer ID**</mark> from Table <mark style="color:purple;">**internetSales**</mark> will match with dimension <mark style="color:blue;">**CustomerKey**</mark> from Table <mark style="color:purple;">**surveyReponse**</mark>.

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2F9ACmtR1lArMkugZcL14N%2Fimage.png?alt=media&#x26;token=0b1808eb-887d-41e9-8700-95d533efedc7" alt=""><figcaption></figcaption></figure>

* Choose the Relationship Type

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FGM78KRowP4PIeVvT7Des%2Fimage.png?alt=media&#x26;token=52bd1633-968c-4c9e-843c-bfd1a5db638d" alt=""><figcaption></figcaption></figure>

* Then, click **`Update Relationship`** to finish the process

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2F2KePZWQw3SwxejUaDIF2%2Fimage.png?alt=media&#x26;token=ad1eebb7-cc78-4f93-83ce-c069c6c8817c" alt=""><figcaption></figcaption></figure>

You can add many relationships once by clicking **`Add Another Relationship`**.

### Editing Relationships via editing Dimensions

You can edit or delete relationships in Dimension details:

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FaS6VhH8yp5lXmWkcUdGp%2Fimage.png?alt=media&#x26;token=b1c0f2f6-f014-4959-a0b0-831bab4e32b8" alt=""><figcaption></figcaption></figure>

* To edit, just change the Relationship Type, then then <mark style="color:blue;">**Update Relationship**</mark> to save you changes;
* To delete, click on the Trash icon <img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FDkX0BMwuXuosIxOL112k%2Fimage.png?alt=media&#x26;token=e506c70d-2064-4527-8c12-cf646cf23b6b" alt="" data-size="original">, then <mark style="color:blue;">**Update Relationship**</mark> to save your deletion.

## 3. View Connected Tables

You can view all table that are connected to the observing table by hover at the related dimension, the number shows how many tables are connected.

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FuuMgoW2K37p80u3tLKQ7%2Fimage.png?alt=media&#x26;token=3d0e867b-f613-4ebe-bfd7-cabec24aeef7" alt=""><figcaption></figcaption></figure>

You can click on **Show All Connected Tables** to view all the tables.

<figure><img src="https://133649292-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIYMCWeQmo9kVg5C6SOyv%2Fuploads%2FxJ0TlPI2CRAU86jVMSAS%2Fimage.png?alt=media&#x26;token=50aac57e-4f81-44f5-86f2-32598574a372" alt=""><figcaption></figcaption></figure>

Click on **Show All Connected Tables** if you wish to hide connected tables.
