How to link data from two tables

This is probably a very simple thing but I'm not sure how to. I have a table which has a field with an id 'a', how can I look up the value of 'a' in table 'b' and have that returned in the response? I am using findMany, will I have to use .join?
3 Replies
Angelelz
Angelelz11mo ago
Please let us see the schema that you're working with and what is the shape of the response that you need.
BenXk
BenXkOP11mo ago
Thanks, I have two tables
export const twoTab = mysqlTable("two_tab", {
seq: int("seq").default(0).notNull(),
seq2: int("seq2").default(0).notNull(),
one: char("one", { length: 3 }).default("").notNull(),
two: char("two", { length: 3 }).default("").notNull(),
id: int("id").autoincrement().notNull(),
export const twoTab = mysqlTable("two_tab", {
seq: int("seq").default(0).notNull(),
seq2: int("seq2").default(0).notNull(),
one: char("one", { length: 3 }).default("").notNull(),
two: char("two", { length: 3 }).default("").notNull(),
id: int("id").autoincrement().notNull(),
And
export const oneTab = mysqlTable("one_tab", {
one: varchar("one", { length: 10 }).default("").notNull(),
two: varchar("two", { length: 10 }).default("").notNull(),
tab: char("tab", { length: 3 }).default("two").notNull(),
export const oneTab = mysqlTable("one_tab", {
one: varchar("one", { length: 10 }).default("").notNull(),
two: varchar("two", { length: 10 }).default("").notNull(),
tab: char("tab", { length: 3 }).default("two").notNull(),
I would like twoTab to have the value of one and two filled with the values from oneTab but under a category key
Angelelz
Angelelz11mo ago
I'm sorry, can you elaborate? maybe a code example could make it easier to understand. The shape of the object you'd like to obtain I feel like if you have the relations defined between those two table, findMany is a great way
Want results from more Discord servers?
Add your server