Basic Selecting: Selecting Different Columns of A Table
Basic Selecting: Selecting Different Columns of A Table
2024-01-04
BASIC SELECTING
FILTERING
Numerical filtering
1
SELECT column_1
FROM table
WHERE numerical_column >= 1970;
Categorical filtering
SELECT column_1
FROM table
WHERE column_2 = 'categorical_value';
–>
SELECT *
FROM table
WHERE column_1 = 'value1' OR column_2 = 'value2'
SELECT *
FROM table
WHERE column_1 IN ('value','vaue','value');
SELECT *
FROM table
WHERE column_1 = 'value_1' AND column_2 = 'value_2';
SELECT *
FROM table
WHERE column BETWEEN 1 AND 2;
Strings matching
SELECT name
FROM table
WHERE name LIKE 'je%';
SELECT name
FROM table
WHERE column_1 LIKE 'Ev_';
NULL TREATMENT
Identification
2
SELECT *
FROM table
WHERE column_1 IS NULL;
AGGREGATE FUNCTIONS
Diferent Functions
SELECT MEAN(column_1)
FROM table;
SELECT ROUND(AVG(column_1),2)
FROM table
WHERE year BETWEEN 2010 AND 2020;
Ordering
SELECT *
FROM table
ORDER BY column_1 ASC, column_2 ASC;
Grouping
FILTERING GROUPS
3
Example with all the verbs
INNER JOIN
Basic Sintax
Simplified sintaxis
Multy Join
SELECT
t1.column_1,
t2.column_2,
t3.column_3
FROM table_1 AS t1
INNER JOIN table_2 AS t2
ON t1.column_x = t2.column_y
INNER JOIN table_3 AS t3
USING(column_with the same name);
4
Outer and Full Joins
ACROSS JOIN
Sintax
SELF JOIN
SELECT
p1.column_1 AS A,
p2.column_1 AS B,
p1.column_2
FROM table_1 AS p1
INNER JOIN table_1 AS p2
ON p1.column_2 = p2.column_2
AND p1.column_1 <> p2.column_1;