> For the complete documentation index, see [llms.txt](https://g4b0.gitbook.io/g4b0-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/sql/operadores-sql.md).

# Operadores SQL

#### SQL Operators

Cuando una sola condición no basta, SQL usa **operadores lógicos** para combinar varias. Los más comunes son `AND`, `OR` y `NOT`.

**Operador `AND`**

Devuelve verdadero **solo si ambas** condiciones son verdaderas:

```sql
condition1 AND condition2
```

En MySQL, cualquier valor distinto de cero es verdadero (devuelve `1`), y `0` es falso. Si una de las dos condiciones falla, el resultado es `0`.

**Operador `OR`**

Devuelve verdadero cuando **al menos una** de las condiciones es verdadera. Solo da falso si ambas fallan.

**Operador `NOT`**

Invierte el valor booleano: lo verdadero se vuelve falso y viceversa. Por ejemplo, `NOT 1 = 1` → `0`.

**Operadores en símbolos**

`AND`, `OR` y `NOT` también se escriben como `&&`, `||` y `!`. El distinto se escribe `!=`.

**Operadores en querie**

```sql
SELECT * FROM logins WHERE username != 'john';              -- todos menos john
SELECT * FROM logins WHERE username != 'john' AND id > 1;   -- ambas condiciones
```

**Precedencia de operadores**

Cuando una query mezcla varias operaciones, el orden de evaluación (de mayor a menor prioridad) es:

1. División `/`, Multiplicación `*`, Módulo `%`
2. Suma `+` y resta `-`
3. Comparación `=`, `>`, `<`, `<=`, `>=`, `!=`, `LIKE`
4. `NOT` (`!`)
5. `AND` (`&&`)
6. `OR` (`||`)

Lo de arriba se evalúa antes que lo de abajo.

**Ejemplo:**

```sql
SELECT * FROM logins WHERE username != 'tom' AND id > 3 - 2;
```

Aquí primero se resuelve la resta (`3 - 2` → `1`), quedando `id > 1`. Luego las comparaciones (`!=` y `>`), y al final el `AND` combina ambas. Resultado: registros donde el username no es `tom` **y** el id es mayor a 1.


---

# 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, and the optional `goal` query parameter:

```
GET https://g4b0.gitbook.io/g4b0-docs/documentation/hacking-web/sql/operadores-sql.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
