sqlwhere-clausekdb+inner-query

Q (kdb): nested where query


What are the ways to in Q to use the results of a nested query in a where clause?

I'm looking for something similar to SQL statement.

select from food where type_id in (
    select type_id from types where type_name = "fruit"
)

Solution

  • select from food where type_id in (exec type_id from types where type_name like "fruit")
    

    Your query was almost correct apart from what you passing to the in predicate and use the like function for string equality. You are passing a table when it only accepts a list. To send the query as a list I use exec which does the job.