Displaying Data Using the SELECT Statement

Previous
Previous
Next
Next

With the SQL SELECT statement, you can query and display data in tables or views in a database.

Example: Using the SQL SELECT Statement to Query All Data From a Table shows how to use SELECT to retrieve data from the employees and departments tables. In this example, the data for all columns in a row (record) of the tables are retrieved using the wildcard (*) notation. Note the use of comments to document the SQL statements. The comments (or remarks) in this example begin with two hyphens (--), but you can also use rem or REM.

Using the SQL SELECT Statement to Query All Data From a Table

-- the following uses the wildcard * to retrieve all the columns of data in
-- all rows of the employees table
SELECT * FROM employees;

-- the following uses the wildcard * to retrieve all the columns of data in
-- all rows of the departments table
SELECT * FROM departments;

Example: Using the SQL SELECT Statement to Query Data From Specific Columns shows how to use SELECT to retrieve data for specific columns of the employees and departments tables. In this example, you explicitly enter the column names in the SELECT statement. For information about the columns in the employees and departments table, see "Managing Database Objects With Object Browser".

Using the SQL SELECT Statement to Query Data From Specific Columns

-- the following retrieves data in the employee_id, last_name, first_name columns
SELECT employee_id, last_name, first_name FROM employees;

-- the following retrieves data in the department_id and department_name columns
SELECT department_id, department_name FROM departments;

Example: Using the SQL SELECT Statement to Query Data in a View shows how to use SELECT to retrieve data from the emp_details_view view.

Using the SQL SELECT Statement to Query Data in a View

-- the following retrieves all columns of data in all rows of the emp_details_view
SELECT * FROM emp_details_view;

-- the following retrieves data from specified columns in the view
SELECT employee_id, last_name, job_title, department_name, country_name, 
       region_name FROM emp_details_view;