> ## Documentation Index
> Fetch the complete documentation index at: https://docs.omniql.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Basics

> Read data with GET operations

The `GET` operation retrieves data from a table.

## Basic Syntax

```sql theme={}
:GET Entity
:GET Entity WHERE conditions
:GET field1, field2 FROM Entity
:GET field1, field2 FROM Entity WHERE conditions
```

## Get All Records

```sql theme={}
:GET User
```

| Database   | Output                |
| ---------- | --------------------- |
| PostgreSQL | `SELECT * FROM users` |
| MySQL      | `SELECT * FROM users` |
| MongoDB    | `db.users.find({})`   |

## Select Specific Columns

```sql theme={}
:GET id, name, email FROM User
```

| Database   | Output                                            |
| ---------- | ------------------------------------------------- |
| PostgreSQL | `SELECT id, name, email FROM users`               |
| MySQL      | `SELECT id, name, email FROM users`               |
| MongoDB    | `db.users.find({}, { id: 1, name: 1, email: 1 })` |

## Simple WHERE Clause

```sql theme={}
:GET User WHERE id = 1
```

| Database   | Output                             |
| ---------- | ---------------------------------- |
| PostgreSQL | `SELECT * FROM users WHERE id = 1` |
| MySQL      | `SELECT * FROM users WHERE id = 1` |
| MongoDB    | `db.users.find({ id: 1 })`         |

## Multiple Conditions

```sql theme={}
:GET User WHERE age > 21 AND status = "active"
```

| Database   | Output                                                     |
| ---------- | ---------------------------------------------------------- |
| PostgreSQL | `SELECT * FROM users WHERE age > 21 AND status = 'active'` |
| MongoDB    | `db.users.find({ age: { $gt: 21 }, status: 'active' })`    |

## Combine Columns and Conditions

```sql theme={}
:GET id, name FROM User WHERE active = true
```

| Database   | Output                                                |
| ---------- | ----------------------------------------------------- |
| PostgreSQL | `SELECT id, name FROM users WHERE active = true`      |
| MongoDB    | `db.users.find({ active: true }, { id: 1, name: 1 })` |

## Limit Results

```sql theme={}
:GET User LIMIT 10
:GET User WHERE active = true LIMIT 5
```

| Database   | Output                         |
| ---------- | ------------------------------ |
| PostgreSQL | `SELECT * FROM users LIMIT 10` |
| MySQL      | `SELECT * FROM users LIMIT 10` |
| MongoDB    | `db.users.find({}).limit(10)`  |

## Skip Results (Pagination)

```sql theme={}
:GET User LIMIT 10 OFFSET 20
```

| Database   | Output                                   |
| ---------- | ---------------------------------------- |
| PostgreSQL | `SELECT * FROM users LIMIT 10 OFFSET 20` |
| MongoDB    | `db.users.find({}).skip(20).limit(10)`   |

## Standalone Aggregates

Aggregates can also be used as standalone operations:

```sql theme={}
:COUNT * FROM User
:COUNT * FROM User WHERE active = true
:SUM amount FROM Order WHERE status = "completed"
:AVG price FROM Product
:MIN created_at FROM User
:MAX total FROM Order
```

| Database   | Output                                                      |
| ---------- | ----------------------------------------------------------- |
| PostgreSQL | `SELECT COUNT(*) FROM users`                                |
| PostgreSQL | `SELECT SUM(amount) FROM orders WHERE status = 'completed'` |

## DISTINCT

Get unique values:

```sql theme={}
:GET User DISTINCT
:GET role FROM User DISTINCT
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Filtering" icon="filter" href="/queries/filtering">
    Advanced WHERE conditions
  </Card>

  <Card title="Sorting" icon="arrow-up-arrow-down" href="/queries/sorting">
    ORDER BY operations
  </Card>
</CardGroup>
