'How can I achieve to this result with Prisma?

I have this Schema:

one A has many B

one B has many C

How can I have all C for each A ?

in Prisma way or at least in raw sql (I've a little big forgot my sql...)

thanks you!



Solution 1:[1]

In the following example, Left Joins seem to be doing what you described

Create Table TableA (id int, something VarChar(20));
Insert Into TableA Values (1, 'A Row No 1');
Create Table TableB (id int, idA Int, something VarChar(20));
Insert Into TableB Values (1, 1, 'B belongs to A');
Create Table TableC (id int, idB Int, something VarChar(25));
Insert Into TableC Values (1, 1, 'C belongs to A1');
Insert Into TableC Values (2, 1, 'C belongs to A1');
Insert Into TableC Values (2, 5, 'does not belong to A1');

Select * From TableA A 
    Left Join TableB B On B.idA = A.id
    Left Join TableC C On C.idB = A.id;

https://dbfiddle.uk/?rdbms=postgres_14&fiddle=f553a8a0a35b4fd6c277a906d1cf1100

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Stefan Wuebbe