#Sql query with multiple inner-joins

4 messages · Page 1 of 1 (latest)

still walrus
#

Hello

I have this SQL query and in the console result is correct.

SELECT rate.alias, rate.id, rate."customerId", rate."contractId"
FROM rate
INNER JOIN public.contract c ON c.id = rate."contractId"
INNER JOIN public.customer c2 ON c2.id = c."customerId"
WHERE rate."customerId" = '5d73e29f-4245-4f20-9a03-ac90b670c63f';

In this case, what is the best way to handle it, with one querybuilder or it is possible via relations without querybuilder?

I am using typeorm as orm.

Thank you.

late flint
#

Why the joins, when you're only selecting and filtering on the rate table? 🤔

still walrus
#

because customer and contract are other tables related with contractId in rate table and customerId in contract table. I am not expert in databases for that point I am asking 🙂
That sql query is only one approach because I am not sure how to do this in typeorm

coral narwhal
#

There is common table expression support for some database drivers in typeorm if that helps