Reading (Querying) Data

Simple Querying

To select all rows and columns from a given table:

SELECT * FROM table_name;

To select all rows but selected columns only:

SELECT column_name, column_name FROM table_name;

Conditional Querying

To select all columns but only rows meeting a specific condition:

SELECT * FROM table_name WHERE condition;

To select only selected columns only from rows meeting a specific condition:

SELECT column_name, column_name FROM table_name WHERE condition;

Distinctive Querying

To get distinct values from a given column:

SELECT DISTINCT column_name FROM table_name;

Aliasing

To temporarily rename a column name in querying results:

SELECT column_name AS new_temporary_column_name FROM table_name;

Pattern Matching

To select only columns meeting a specific pattern:

SELECT * table_name WHERE column_name LIKE pattern;

In a pattern, _ stands for any single character and % stands for `zero or more characters.

LIKE pattern always regards an entire string. Therefore to look for a match within an entire string the pattern should start and end with %.