SELECT * FROM table_name;When you use the SELECT statement, you're asking the database to look through all of its tables and find specific information for you. This query returns every column and every row of the table called table_name.
Selecting specific columns
SELECT column1, column2, column3 FROM table_name;This query returns every row of column1, column2, and column3 from table_name.
SELECT * FROM table_name WHERE column1 = "expression";This query returns every column from table_name - but only those rows where the value in column1 is "expression". Obviously, this can be something in any other data format, too.
Comparison operators help you compare two values. (Usually, you define a value in your query and values in your SQL table.) Mostly, they are mathematical symbols, with a few exceptions:
| Comparison operator | Meaning |
| ------------------------------------------------ | -------------------------------------------------------------------------------------- |
| = | Equal to |
| <> | Not equal to |
| != | Not equal to |
| < | Less than |
| <= | Less than or equal |
| > | Greater than |
| >= | Greater than or equal to |
| LIKE "%expression%" or NOT LIKE "%expression%" | Case insensitive string comparison, % matches a sequence of zero or more characters |
| IN ("exp1", "exp2", "exp3") | Contains any of "exp1", "exp2", or "exp3" |
| BETWEEN ... AND ... | The number is within a range of two values, for example, column BETWEEN 1.5 AND 10.5 |
| NOT IN (...) or NOT BETWEEN ... AND ... | Not exist in a list or range of two values |Multiple conditions
You can use more than one condition to filter. For that, we have two logical operators: OR, AND.
SELECT * FROM table_name ORDER BY column1;This query returns every row and column from table_name, ordered by column1, in ascending order (by default).
SELECT * FROM table_name ORDER BY column1 DESC;This query returns every row and column from table_name, ordered by column1, in descending order.
SELECT * FROM table_name LIMIT 10;The LIMIT clause is like a filter that helps you to limit the amount of information you want to see. This query returns every column and the first ten rows from table_name.
SELECT * FROM table_name LIMIT 10 OFFSET 20;The OFFSET clause in SQL is used to specify the number of rows to skip before starting to return rows in a query. It is typically used in combination with the LIMIT clause to paginate the results of a query.
Correct keyword order SQL is extremely sensitive to keyword order. So make sure you keep it right:
SELECTFROMWHEREORDER BYLIMIT