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:

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 : )
KNKristian Notari5/8/2023
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!!

Looking for more? Join the community!

Recommended Posts
Is there a way to execute an ExpressionBuilder?Using the expression hasDogNamed example from the docs ``` const eb = expressionBuilder<DB, 'personArgument of type 'string' is not assignable to parameter of type 'DynamicReferenceBuilder<never>'.The following statement, is giving me the error on the title ```ts fn("round", [fn.min("ld.price_btcHow do Date columns works?I am learning Kysely from the website, at the getting started section I can see the following line: Advice on building plugin for working with parametersI am currently working on a driver for YDB https://github.com/Gaspero/kysely-ydb YDB dialect expectMysql Query execution never endsHello, I have a question regarding my new integration of kysely in trpc. I wanted to port my prisma How to do join with raw sql snippets?How can I do this join with kysely? `left join videos on videos.id = CAST(highlights_content.item ASMore elegant way to handle nested relations?Can someone come up with more elegant solution for handling relations than this? I've modified the eJoin DATE_TRUNCHey, sorry if this is already answered somewhere. I couldn't find anything 😦 I want to translate Why does kysely-codegen generate the schema in node_modules?Like probably many people here, I use https://github.com/RobinBlomberg/kysely-codegen . By default, Any plan to complete the Postgres dialect?Hey there, Is there any plan (or a tracking issue) to complete the Postgres dialect with its specifiConvert date to timestamptzHello. I'm trying to convert the following query from TypeORM querybuilder to Kysely: itemReposiShorthand way to pass the entire update object inside of doUpdateSet when updating multiple values.Greetings! Thanks for developing Kysely, some of the stuff that it does actually blows my mind. I o