Select statements is used to query data from tables and views.
Example:
SELECT column1, column2, column3 FROM table_name; # Query all columns in a table. SELECT * FROM rental ; # Queries specific columns. SELECT country_name FROM address ; --or SELECT first_name, email, username FROM staff ; # If you do not specify a specific column and use the '*' expression, all row and column in the table you specified will be displayed. Select * from rental ; # When you want to extract values from more than one column in the table, if you specify the column name one by one with ',' , the query result will appear in the same order. SELECT address_id FROM address ; SELECT country_id FROM city ; SELECT first_name, email, username FROM staff ;
Column Concatenation
The SQL statement returns the values of the first_name and last_name lines in one column, and the email column in the other line.
SELECT first_name || ' ' || last_name, email FROM customer;
Alias
An alias is given to the column during the query.
SELECT column_name AS alias_name FROM table_name; # The following query is used to combine the first_name and last_name into a single column and give the column an alias 'name'. SELECT first_name || ' ' || last_name as name , email FROM customer; SELECT 20/5 as result ; SELECT last_name as surname , first_name from customer ; SELECT first_name, last_name surname FROM customer; # If the alias of the column contains spaces, the alias is written in double quotes. SELECT first_name || ' ' || last_name “full name” FROM customer;