K
Join ServerKysely
help
Noob Question: SQL INSERT that combines static values with a SELECT statement
Hey Kysely community! I'm just getting into Kysely and I have a question about how I could run the following query with Kysely:
I could get an INSERT + SELECT query to work, but wasn't sure how to add static values into the mix.
Thanks in advance : )
INSERT INTO employees (employee_id, first_name, last_name, department_id)
VALUES (1234, 'John', 'Doe',
(SELECT department_id
FROM departments
WHERE department_name = 'Sales')
);
I could get an INSERT + SELECT query to work, but wasn't sure how to add static values into the mix.
Thanks in advance : )
kysely.insertInto('employees').values({
employee_id: 1234,
first_name: 'John',
last_name: 'Doe',
department_id: eb => eb.selectFrom('departments').select('department_id').where(...)
})
does this work?
can't test it right now
That's exactly it, thank you!!