#concat two Prisma.sql queries.

7 messages · Page 1 of 1 (latest)

quasi oyster
#

I have two pretty complex queries which i created manually using

const a = Prisma.sql(...)
const b = Prisma.sql(...)

In some cases and since both return the same data type, I would like to run them in one go concatenated using (QUERY1) UNION (QUERY2).

So, my question is: How can I concat two Prisma.sql queries?

past sageBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

quasi oyster
#

any ideas anyone?

woeful siren
#

Hi @quasi oyster

Would this example work for you?

const query1 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString1}`;
const query2 = Prisma.sql`SELECT id, name FROM "User" WHERE name = ${inputString2}`;

const combinedQuery = Prisma.sql`${query1} UNION ${query2}`;

const result = await prisma.$queryRaw(combinedQuery);
quasi oyster
#

yes!

#

So I can simply wrap the queries in a new Prisma.sql?

woeful siren
#

Yes you can