Skip to main content

SQL

SQL query syntax and common operations

Database

Basic Queries

SELECT * FROM table

Select all columns

SELECT col1, col2 FROM table

Select specific columns

SELECT DISTINCT col FROM table

Unique values only

SELECT * FROM table LIMIT 10

Limit results

Filtering

WHERE col = 'value'

Equals

WHERE col != 'value'

Not equals

WHERE col > 10

Greater than

WHERE col LIKE '%text%'

Pattern match

WHERE col IN (1, 2, 3)

In list

WHERE col BETWEEN 1 AND 10

Range

WHERE col IS NULL

Null check

AND / OR

Combine conditions

Sorting & Grouping

ORDER BY col ASC

Sort ascending

ORDER BY col DESC

Sort descending

GROUP BY col

Group rows

HAVING COUNT(*) > 1

Filter groups

Joins

INNER JOIN t2 ON t1.id = t2.id

Matching rows only

LEFT JOIN t2 ON t1.id = t2.id

All left + matching

RIGHT JOIN t2 ON t1.id = t2.id

All right + matching

FULL OUTER JOIN

All rows from both

Aggregates

COUNT(*)

Count rows

SUM(col)

Sum values

AVG(col)

Average value

MIN(col) / MAX(col)

Min/max value

Data Modification

INSERT INTO t (col) VALUES (val)

Insert row

UPDATE t SET col = val WHERE

Update rows

DELETE FROM t WHERE

Delete rows

TRUNCATE TABLE t

Delete all rows

Table Operations

CREATE TABLE t (col TYPE)

Create table

ALTER TABLE t ADD col TYPE

Add column

DROP TABLE t

Delete table

CREATE INDEX idx ON t(col)

Create index

Privacy-First Developer Toolkits - 35+ Browser-Based Tools