SQL Strategy - A site to master SQL while executing it on the Web
Home >> SQL Strategy - Basics of SELECT statement (1)
Basics of SELECT statement (1)
Learn the basic syntax of the SELECT statement.
1. basic SELECT minute syntax
--Show all data
SELECT
Column name,Column name...
FROM
Table name
■How to write a SELECT statement
When using a SELECT statement, after the SELECT statement, enter a comma-separated list of column names; you can also use SELECT * (asterisk) to display all columns. Then, after the FROM statement, enter the Table name.
■practice
Now for the exercise, I will give you two questions.
Practice (1/2) Questions
From the EMP table, display ENAME (employee name), JOB (job), and SAL (salary).
Practice (1/2) Answers
SELECT ENAME,JOB,SAL FROM EMP
Describe the items to be displayed after SELECT, separated by commas, and the table after FROM.
Practice (2/2) Questions
Use * (asterisk) to display all records in the EMP table.
Practice (2/2) Answers
SELECT * FROM EMP
If you use "*", it means the same as if you had selected all columns.
The SELECT statement can contain arithmetic expressions to display the results of calculations. The following operators can be used. Parentheses can also be used to specify the precedence of calculations.
operator
meaning
+
addition
-
subtraction
*
multiplication
/
division (arith)
Now for the exercise, I will give you one Question.
Exercise Question
You have decided to increase an employee's salary by 2%; from the EMP table, show the employee's name (ENAME) and the salary multiplied by 1.02 (SAL).
Exercise answer
SELECT NAME,SAL * 1.02 FROM EMP
Arithmetic expressions can be used with the column operator number.