Question: Can I use power query to combine two tables, so that each rows in table 1 contains all rows in table 2.

For example table 1 includes: customer a, customer b, customer c
table 2 includes: product 1, product 2.

I want to combine two tables into table 3: customer a product 1, customer a product 2, customer b product 1, customer b product 2, customer c product 1, customer c product 2

Answer: 
You have to build some form of secondary index to accomplish this efficently.

Use a Set
---------

You can use a set, and create a set for each company, and add each key to it.

```
SADD myhash:Company:BMW myhash1 myhash3 myhash5
SADD myhash:Company:Benz myhash2 myhash7
SADD myhash:Company:Honda myhash4
SADD myhash:Company:Toyota myhash6

```

Then when you want to query it, you would just use SCARD, so if you wanted to know how many BMWs there were you'd just run

```
SCARD myhash:Company:BMW

```

With Redis Stack
----------------

[Redis Stack](https://redis.io/docs/stack/get-started/) has native secondary indexing capabilities which you can leverage here this is much easier to maintain (and can actually work across shards in a scaled out environment if need be). You'd just need to create the secondary index

```
FT.CREATE hashes PREFIX 1 myhash SCHEMA company tag

```

Then you'd just need to query them (if you don't care to get the actual cars matching your query back just pass in `LIMIT 0 0`

```
FT.SEARCH hashes "@company:{BMW}" LIMIT 0 0

```
The thing with non-relational databases is that you have to make relations by hand if needed. So here you are "obliged" to have another key holding this information.

1. If you want all informations, you can have a set key holding it like :

```
SADD BMW myhash1 
//use SCARD to know how many BMW there are
SCARD BWM

```

2. If you only want to know the number of BMWs you can have a simple key holding a number like :

```
INCR BMW //autoset to 0 before applying INCR, holds 1 after this command
//use GET to have the number of BMWs
GET BWM //returns 1
//if you want to delete a hash you can use INCRBY to update the number
INCRBY BMW -1

```