There are three ways we can select a column or some columns data with a select query. This Oracle tutorial will show you different ways with the help of syntax and examples.
This page contains (Skip to topic)..
SELECT a column data
We can select a column data by using column name. So the syntax for the same is as follows.
SELECT column_name FROM table_name;
You can refer to this syntax and try to get all the ids from the employees table. Please note, I need only one column data .e. employee_id.
SELECT employee_id FROM employees;
This is basically useful when you will understand how can we filter SQL result with SQL Where clause. e.g. Finding the “employee ids” of the employee whose hire_date is after 07-03-2006.
Select a column data using table_name.column_name
Whenever we select a column or all columns, Oracle implicitly accesses them with the “xyz.column_name” format. This basically tells Oracle that, get me column_name from the xyz table.
The syntax for this would be,
SELECT table_name.column_name, table_name.column_name, ... FROM table_name;
Now, let us select all columns from the employee table in this way.
SELECT employees.employee_id FROM employees;
SELECT a column data using table_aliase.column_name
Its syntax is,
SELECT table_aliase.column_name1, table_aliase.column_name2, .... FROM table_name table_aliase;
With reference to the above syntax, let us try to select the employee_id column from the employees’ table.
SELECT emp.employee_id, emp.first_name FROM employees emp;
We understood how to select a column, all columns in the Oracle database. Now, let us understand on SELECT something FROM dual table in the next post.