> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/misc/databases/sql-databases/sql-language.md).

# SQL Language

[Structured Query Language](https://en.wikipedia.org/wiki/SQL) (SQL) is a [domain-specific language](https://en.wikipedia.org/wiki/Domain-specific_language) used to manage data, especially in a [relational database management system](https://en.wikipedia.org/wiki/Relational_database_management_system) (RDBMS). It is particularly useful in handling [structured data](https://en.wikipedia.org/wiki/Data_model), i.e., data incorporating relations among entities and variables.

## SELECT Statement

[`SELECT`](https://dev.mysql.com/doc/refman/8.4/en/select.html) is used to retrieve rows selected from one or more tables, and can include [`UNION`](https://dev.mysql.com/doc/refman/8.4/en/union.html) operations and subqueries. [`INTERSECT`](https://dev.mysql.com/doc/refman/8.4/en/intersect.html) and [`EXCEPT`](https://dev.mysql.com/doc/refman/8.4/en/except.html) operations are also supported.

Select all columns (\*) from the `users`table filtering for the user\_name `leon` only

```sql
SELECT * FROM users WHERE user_name='leon'
```

### References

SELECT Statement - MySQL: <https://dev.mysql.com/doc/refman/8.4/en/select.html>

SELECT Statement - SQLite: <https://www.sqlite.org/lang_select.html>

Select (SQL) - Wikipedia: <https://en.wikipedia.org/wiki/Select_(SQL)>

## Find table names

### SQLite

To find out the name of the tables in a SQLite database

```sql
SELECT tbl_name FROM sqlite_master
```

## Resources

SQL - Wikipedia: <https://en.wikipedia.org/wiki/SQL>
