SELECT Queries
Basic SELECT
Section titled “Basic SELECT”Select All Columns
Section titled “Select All Columns”-- Using SQL-like syntaxselect * from users
-- Transpiled SQLSELECT * FROM usersSelect with Type Name
Section titled “Select with Type Name”-- Selects all columns from the tableselect User
-- Transpiled SQLSELECT * FROM UserSelect Specific Columns (Shape Syntax)
Section titled “Select Specific Columns (Shape Syntax)”select User { id, name, email }
-- Transpiled SQLSELECT id, name, email FROM UserFiltering
Section titled “Filtering”Use the filter keyword to add WHERE conditions:
-- Simple filterselect User { name, email } filter active = true
-- Transpiled SQLSELECT name, email FROM User WHERE active = true-- String comparisonselect User { name } filter role = "admin"
-- Transpiled SQLSELECT name FROM User WHERE role = 'admin'Alternative: WHERE Clause
Section titled “Alternative: WHERE Clause”BQL also supports the traditional where keyword:
select * from users where age >= 18
-- Transpiled SQLSELECT * FROM users WHERE age >= 18Ordering
Section titled “Ordering”Use order by to sort results:
-- Ascending (default)select User { name } order by name
-- Descendingselect User { name } order by created_at desc
-- Transpiled SQLSELECT name FROM User ORDER BY created_at DESCLimiting Results
Section titled “Limiting Results”select User { name } order by score desc limit 10
-- Transpiled SQLSELECT name FROM User ORDER BY score DESC LIMIT 10Complete Example
Section titled “Complete Example”select User { id, name, email, score}filter active = trueorder by score desclimit 10
-- Transpiled SQLSELECT id, name, email, scoreFROM UserWHERE active = trueORDER BY score DESCLIMIT 10