Header Ads

Header ADS

SELECT Statement

SELECT Statement








Selecting All Columns

SELECT *
FROM employees;



We can display all columns of data in a table by following the SELECT keyword with an
asterisk (*). In the example in the slide, the EMPLOYEES table contains 11 columns:
employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, manager_id and department_id. The table contains 108 rows.
We can also display all columns in the table by listing all the columns after the SELECT keyword.
For example, the following SQL statement (like the example in the slide) displays all columns and all
rows of the EMPLOYEES table:

SELECT employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct, manager_id, department_id
FROM employees;



Selecting Specific Columns



SELECT employee_id, last_name, department_id, salary
FROM employees;


We can use the SELECT statement to display specific columns of the table by specifying the column
names, separated by commas. The example in the slide displays all the employee numbers, last names, department numbers, and salaries from the EMPLOYEES table.
In the SELECT clause, specify the columns that you want in the order in which you want them to
appear in the output.


Writing SQL Statements

1. SQL statements are not case-sensitive.
2. SQL statements can be entered on one or more lines.
3. Keywords cannot be abbreviated or split across lines.
4. Clauses are usually placed on separate lines.
5. Indents are used to enhance readability.
6. In SQL Developer, SQL statements can be optionally terminated by a semicolon (;). Semicolons are required when you execute multiple SQL statements.
7. In SQL*Plus, you are required to end each SQL statement with a semicolon (;).


No comments

Theme images by Deejpilot. Powered by Blogger.