SQL
DELETE FROM table_name WHERE condition;
DELETE FROM table_name; -- All records!SELECT COUNT(column_name) FROM table_name WHERE condition;
SELECT COUNT(*) FROM table_name;UPDATE table_name SET col = value WHERE condition;DROP TABLE table_name;WITH RowFromOtherTable AS (
SELECT id FROM other_table WHERE name = 'A')
SELECT * FROM this_table WHERE other_id = (SELECT id FROM SpecifiedPlan);Selects record that have the same value in two tables.
SELECT left.id, left.name, right.date FROM left
INNER JOIN right
ON left.id = right.id
WHERE left.customer = '100';Selects all records where there's a match in the first (left) table or the second (right) table.
SELECT left.id, left.name, right.date FROM left
FULL JOIN right
ON left.id = right.id;Also supports WHERE.
SELECT * FROM information_schema.tables;
SELECT * FROM information_schema.tables WHERE table_schema='schema1';SELECT catalog_name,schema_name FROM information_schema.schemata;Note: catalog_name is DB name.
SELECT pid, datname, state, current_timestamp-least(query_start,xact_start) age, application_name, usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>'
AND query NOT ILIKE '%pg_stat_activity%'
AND usename!='rdsadmin'
ORDER BY query_start desc;