# New to QlikView

Discussion board where members can get started with QlikView.

Announcements
Modernize Your QlikView Deployment webinar, Nov. 3rd. REGISTER
cancel
Showing results for
Did you mean:
Highlighted
Creator III

## Help and info with Cartesian Product

Hi can someone give me information and description on when a Cartesian product is made?

-Description

-Benefits in some cases

-how it is created

anything else that you can think of

Many thanks guys

1 Solution

Accepted Solutions
Highlighted
Specialist III

Ok,

What is a Cartesian product?

When you join two tables (A and B) together which have no common fields, all combinations of your first table will be joined to all combinations of your second table.

For example

Table 1

Field 1     Field 2

f1v1          f2v1

f1v2          f2v2

Table 2

Field 3     Field 4

f3v1          f4v1

f3v2          f4v2

Cartesian product

Field 1     Field 2     Field 3     Field 4

f1v1          f2v1          f3v1          f4v1

f1v1          f2v1          f3v2          f4v2

f1v2          f2v2          f3v1          f4v1

f1v2          f2v2          f3v2          f4v2

the main disadvantage is the sheer amount of memory required when dealing with large tables. Also you will be duplicating data with little benefit. Why not just keep your source tables separate if they have no relationship?

Benefits

The one time I would consider using a cartesian join is when creating an As At calendar. There are several examples of how to do this here on the community.

Hope that helps.

Marcus

5 Replies
Highlighted
MVP & Luminary

I think you should start here: Cartesian product - Wikipedia. What is the aim behind your question?

- Marcus

Creator III

to give an overview on what it is and why it is bad and how it is formed all in a short summary

Highlighted
Specialist III

Ok,

What is a Cartesian product?

When you join two tables (A and B) together which have no common fields, all combinations of your first table will be joined to all combinations of your second table.

For example

Table 1

Field 1     Field 2

f1v1          f2v1

f1v2          f2v2

Table 2

Field 3     Field 4

f3v1          f4v1

f3v2          f4v2

Cartesian product

Field 1     Field 2     Field 3     Field 4

f1v1          f2v1          f3v1          f4v1

f1v1          f2v1          f3v2          f4v2

f1v2          f2v2          f3v1          f4v1

f1v2          f2v2          f3v2          f4v2

the main disadvantage is the sheer amount of memory required when dealing with large tables. Also you will be duplicating data with little benefit. Why not just keep your source tables separate if they have no relationship?

Benefits

The one time I would consider using a cartesian join is when creating an As At calendar. There are several examples of how to do this here on the community.

Hope that helps.

Marcus

Highlighted
MVP & Luminary

A cartesian product itself isn't bad - it depends on what do you want to do. Usually it will be created with joins between tables and if there are no common keys you could get depending on the join-type a cartesian product. The more important point will therefore be to understand how joins work and when they could have unexpected results - when maybe the keys are missing or in a different relation as assumed.

Therefore beside the above mentioned link take a look here: Join (SQL) - Wikipedia

- Marcus

Highlighted