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"
)
Using Nested Queries with SELECT. In SQL, a query is an operation that retrieves data from a table in a database and always includes a SELECT statement. A nested query is a complete query embedded within another operation.
A Subquery or Inner query or a Nested query is a query within another SQL query and embedded within the WHERE clause. A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.
A nested query is a query that has another query embedded within it. The embedded query is called a subquery. A subquery typically appears within the WHERE clause of a query. It can sometimes appear in the FROM clause or HAVING clause.
A subquery in a WHERE clause can be used to qualify a column against a set of rows. For example, the following subquery returns the department numbers for departments on the third floor. The outer query retrieves the names of employees who work on the third floor. WHERE floor = 3);
while that's the direct answer to your question, the best way do this is probably foreign keys:
q)types:([type_id:`apple`orange`cucumber]type_name:`fruit`fruit`vegetable)
q)food:([type_id:`types$`apple`orange`cucumber]price:3?2.)
q)meta food
c | t f a
-------| ---------
type_id| s types
price | f
q)select from food where type_id.type_name=`fruit
type_id| price
-------| ---------
apple | 0.4593231
orange | 1.383906
q)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With