Subqueries in SQLY allow you to nest one query inside another, providing powerful ways to filter, aggregate, and retrieve data dynamically.
Subqueries can be used to filter results based on another query.
query:
select: [id, name, email]
from: customers
where:
id:
in:
subquery:
select: customer_id
from: orders
group_by: customer_id
having:
count: orders.id
gt: 3A subquery can be used inside the select statement to fetch additional computed values.
query:
select:
- id
- name
- email
- last_order:
subquery:
select: max(order_date)
from: orders
where:
customer_id: customers.id
from: customersSubqueries can act as temporary tables within a query.
query:
select: [customer_id, total_spent]
from:
subquery:
select: [customer_id, sum: total_price as total_spent]
from: orders
group_by: customer_id
order_by: total_spent DESC
limit: 5- Use subqueries in
whereto filter based on nested queries. - Use subqueries in
selectto retrieve computed values. - Use subqueries in
fromto create temporary result sets.