SELECT
Retrieve rows from your tables using SQL SELECT statements.Overview
SELECT retrieves rows from one or more tables. It is the most frequently used SQL statement.
Basic Syntax
SELECT column1, column2 FROM table_name WHERE condition ORDER BY column1 ASC LIMIT 10;
Examples
Get All Rows
SELECT * FROM users;
Select Specific Columns
SELECT id, name, email FROM users;
Filter with WHERE
SELECT * FROM posts WHERE is_published = 1;
Multiple Conditions
SELECT * FROM posts WHERE is_published = 1 AND category = 'technology';
Sorting
SELECT * FROM posts ORDER BY created_at DESC;
Pagination
SELECT * FROM posts ORDER BY created_at DESC LIMIT 10 OFFSET 20;
LIMIT caps the number of rows returned. OFFSET skips the first N rows — useful for pagination (page 3 with 10 items per page = LIMIT 10 OFFSET 20).
JOIN
SELECT posts.id, posts.title, users.name AS author FROM posts JOIN users ON posts.user_id = users.id WHERE posts.is_published = 1 ORDER BY posts.created_at DESC;
Aggregation
SELECT category, COUNT(*) AS total FROM posts GROUP BY category ORDER BY total DESC;
Using SELECT via the API
For simple reads, use the CRUD GET endpoint — it handles filtering, sorting, and pagination through query parameters without writing raw SQL.
For complex queries (JOINs, aggregations, subqueries), use the SQL API:
const result = await datasquirel.api.sql({ key: process.env.DATASQUIREL_API_KEY, params: { query: "SELECT posts.id, posts.title, users.name AS author FROM posts JOIN users ON posts.user_id = users.id WHERE posts.is_published = 1 ORDER BY posts.created_at DESC LIMIT 20", }, });