SQL
Examples
Select all columns from the table called `table_name`:  
```sql
SELECT *
FROM table_name;
```  
Select all columns from the table using the `FROM`-first syntax:  
```sql
FROM table_name
SELECT *;
```  
Select all columns using the `FROM`-first syntax and omitting the `SELECT` clause:  
```sql
FROM table_name;
```  
Select all columns from the table called `table_name` through an alias `tn`:  
```sql
SELECT tn.*
FROM table_name tn;
```  
Select all columns from the table `table_name` in the schema `schema_name`:  
```sql
SELECT *
FROM schema_name.table_name;
```  
Select the column `i` from the table function `range`, where the first column of the range function is renamed to `i`:  
```sql
SELECT t.i
FROM range(100) AS t(i);
```  
Select all columns from the CSV file called `test.csv`:  
```sql
SELECT *
FROM 'test.csv';
```  
Select all columns from a subquery:  
```sql
SELECT *
FROM (SELECT * FROM table_name);
```  
Select the entire row of the table as a struct:  
```sql
SELECT t
FROM t;
```  
Select the entire row of the subquery as a struct (i.e., a single column):  
```sql
SELECT t
FROM (SELECT unnest(generate_series(41, 43)) AS x, 'hello' AS y) t;
```  
Join two tables together:  
```sql
SELECT *
FROM table_name
JOIN other_table
ON table_name.key = other_table.key;
```  
Select a 10% sample from a table:  
```sql
SELECT *
FROM table_name
TABLESAMPLE 10%;
```  
Select a sample of 10 rows from a table:  
```sql
SELECT *
FROM table_name
TABLESAMPLE 10 ROWS;
```  
Use the `FROM`-first syntax with `WHERE` clause and aggregation:  
```sql
FROM range(100) AS t(i)
SELECT sum(t.i)
WHERE i % 2 = 0;
```