DEV Community

Edrick Ee
Edrick Ee

Posted on • Edited on

Basic query for PostgreSQL to remember

Basic query:

SELECT column, column, column
FROM table
WHERE table.column = ${whatever}
Enter fullscreen mode Exit fullscreen mode

Query with nested array with join table:

SELECT column1, column2, json_agg(json_build_object('key', value) AS name_your_key
FROM table1
LEFT JOIN table2
ON table1.id = table2.table1.id
WHERE table1.id = ${whatever}
GROUP BY column1, column2
Enter fullscreen mode Exit fullscreen mode

Top comments (0)