Question: I have the following data types that I want to store in a relational database:

```
Phase {
  product: Product;
  name: string;
  phases: Phase[]; - I want this to be as subset of phases from the **product.phases**
}

Product {
  name: string;
  phases: Phase[];
}

```

Can this be done with a relational database?

To clarify the question: 
 I have a list of products. Each product has a list of phases. Each phase in the list also has a list of phases.
I want a restriction to the `product->phases->phases` to contain phases only from the `product->phases`.

Example: 

```
Phases - [{ 
  name: 'phase1', 
  product: 'product1' phases: 'I want this to be a subset of ['phase1', 'phase2', 'phase3'] (the phases the 'product1' has)' }]

Products - [{ 
  name: 'product1', 
  phases: ['phase1', 'phase2', 'phase3'] 
}]

```

Can I make such restriction in a relational database?

Answer: 
I am assuming from your question that a product has phases but not the other way around which is a "One to Many" relation but the following structure can also represent "Many to Many" relations which go in both directions:

```
create table phase(
  phase_id int primary key,
  phase_name varchar(20)
);

create table product(
  product_id int primary key,
  product_name varchar(20)
);

create table product_phases(
  phase_id int,
  product_id int,
  primary key (phase_id,product_id),
  foreign key (phase_id) references phase(phase_id),
  foreign key (product_id) references product(product_id) 
);

```
Because, you want phase to refer to itself as well as other table, you will need to have a table that references to itself and a reference to other table. So, your tables design would be something like this:

```
Table Product:
Id        --Primary key for this table.
Name      -- Name of the Product.

Table Phase:
Id        --Primary key for this table.
Name      -- Phase Name
ProductId -- Foreign Key Reference To Product Table.
ParentId  -- Self reference to this Phase Table.

```