1. Select to retrieve a single column
SELECT column name From Table Name
When the output data is not sorted, the order is not certain.
2. Select to retrieve multiple columns
SELECT column name, column name 1, column name 2 FROM Table Name
3. Retrieve all columns
SELECT * FROM Table Name
Generally, you are advised not to use the wildcard * unless you really need each column in the table *. This will reduce the search and application performance.
4. Retrieve different rows
Use DISTINCT keywords
Select distinct column name FROM Table Name
If select distinct column name 1 and column name 2 FROM table name, all rows will be retrieved unless the two columns are different. That is to say, the data of all two columns is retained.
5. Restrict returned results
SELECT column name FROM table name LIMIT 5;
Indicates that no more than five rows are returned.
SELECT column name FROM table name LIMIT;
Equivalent
SELECT column: FROM Table Name: LIMIT 5 OFFSET 100;
Returns the five rows starting with row 100. The first number is the start position, and the second number is the number of rows to be retrieved.
Note: Row 0 retrieves the first row 0 instead of Row 1. Therefore, LIMIT1 and 1 retrieve the second row instead of the first row.
6. Use a fully qualified table name
SELECT prosucts. prod_name FROM crashcourse. prosucts;