> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/database/sql-databases/sql-fundamentals/sql-clauses.md).

# SQL Clauses

## Description

SQL clauses are keywords that specify conditions or modify the behavior of SQL statements. They form the building blocks of SQL queries.

## Different Clauses

### **SELECT Clause**:

Specifies the columns to be retrieved.

**Example:**

```sql
SELECT name, salary FROM employees;
```

### **FROM Clause**:

Specifies the table(s) from which to retrieve the data.

**Example:**

```sql
SELECT name, salary FROM employees;
```

### **WHERE Clause**:

Filters the rows based on a specified condition.

**Example:**

```sql
SELECT name, salary FROM employees WHERE department_id = 10;
```

### **GROUP BY Clause**:

Groups rows that have the same values in specified columns into aggregated data.

**Example:**

```sql
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id;
```

### **HAVING Clause**:

Filters groups based on a specified condition (used with `GROUP BY`).

**Example:**

```sql
SELECT department_id, AVG(salary) FROM employees GROUP BY department_id HAVING AVG(salary) > 50000;
```

### **ORDER BY Clause**:

Sorts the result set based on one or more columns.

**Example:**

```sql
SELECT name, salary FROM employees ORDER BY salary DESC;
```

### **JOIN Clause**:

Combines rows from two or more tables based on a related column.

**Example:**

```sql
SELECT employees.name, departments.dept_name
FROM employees
JOIN departments ON employees.dept_id = departments.dept_id;
```

### **INSERT INTO Clause**:

Adds new rows to a table.

**Example:**

```sql
INSERT INTO employees (name, department_id, salary) VALUES ('John Doe', 10, 60000);
```

### **UPDATE Clause**:

Modifies existing rows in a table.

**Example:**

```sql
UPDATE employees SET salary = salary + 5000 WHERE department_id = 10;
```

### **DELETE Clause**:

Removes rows from a table.

**Example:**

```sql
DELETE FROM employees WHERE department_id = 10;
```

### **LIMIT/OFFSET Clause**:

Specifies the number of rows to return or skip (supported in databases like MySQL, PostgreSQL).

**Example:**

```sql
SELECT * FROM employees LIMIT 10 OFFSET 20;
```

### **DISTINCT Clause**:

Removes duplicate rows from the result set.

**Example:**

```sql
SELECT DISTINCT department_id FROM employees;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/database/sql-databases/sql-fundamentals/sql-clauses.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
