( sql question ) How do you join full tables with select columns from other table?

Hi everyone. I'm new to Drizzle. I have this TypeScript function:
export const fetchAllServicesWithProfiles = async () => {
const result = await db
.select()
.from(services)
.innerJoin(serviceProfiles, eq(services.id, serviceProfiles.serviceId));
return result;
};
export const fetchAllServicesWithProfiles = async () => {
const result = await db
.select()
.from(services)
.innerJoin(serviceProfiles, eq(services.id, serviceProfiles.serviceId));
return result;
};
I realize this is a basic SQL question. This is currently returning one object of services and another of serviceProfiles per entry in the services table. Bear in mind there is one serviceProfile per services entry, in a one-to-one relationship. Instead of two separate objects per each entry of services table, how can I return a single object with all entries of services table plus select columns from serviceProfiles table, all merged into a single object per services table entry? Thanks in advance!
Solution:
select({id: services.id, …}).from(…).innerJoin(…)
Jump to solution
2 Replies
Solution
arily
arily8mo ago
select({id: services.id, …}).from(…).innerJoin(…)
nr7751
nr7751OP8mo ago
@arily , it worked! ```typescript export const fetchAllServicesWithProfiles = async () => { const result = await db .select({ id: services.id, category: services.category, service: services.service, description: services.description, unit: services.unit, duration: services.duration, personnel: services.personnel, included: services.included, price: serviceProfiles.price, sale: serviceProfiles.sale, saleExpiresBy: serviceProfiles.saleExpiresBy, popularity: serviceProfiles.popularity, }) .from(services) .innerJoin(serviceProfiles, eq(services.id, serviceProfiles.serviceId)); return result; }; Thanks a bunch!
Want results from more Discord servers?
Add your server