# SQL, how to use SELECT

> Learn how to get data from a SQL table with the SELECT command, choosing columns, counting rows with COUNT, and filtering results with the WHERE clause.

Author: Flavio Copes | Published: 2020-03-28 | Canonical: https://flaviocopes.com/sql-select/

You can get data out of tables using the `SELECT` command.

Get all rows and columns:

```sql
SELECT * FROM people;
```

```
 age |  name  
-----+--------
  37 | Flavio
   8 | Roger
```

Get only the `name` column:

```sql
SELECT name FROM people;
```

```
  name  
--------
 Flavio
 Roger
```

Count the items in the table:

```sql
SELECT COUNT(*) from people;
```

```
 count 
-------
     2
```

By the way, once your tables grow, queries with `WHERE` clauses can get slow without the right index. I built a free [index advisor](https://flaviocopes.com/tools/index-advisor/) that suggests the `CREATE INDEX` statement for the shape of your query.

You can filter rows in a table adding the `WHERE` clause:


```sql
SELECT age FROM people WHERE name='Flavio';
```

```
 age 
-----
  37
```

The results of a query can be ordered by column value, ascending (the default) or descending, using ORDER BY:

```sql
SELECT * FROM people ORDER BY name;
```

```sql
SELECT * FROM people ORDER BY name DESC;
```
