• Skip to primary navigation
  • Skip to main content

Tech Honey

The #1 Website for Oracle PL/SQL, OA Framework and HTML

  • Home
  • HTML
    • Tags in HTML
    • HTML Attributes
  • OA Framework
    • Item in OAF
    • Regions in OAF
    • General OAF Topics
  • Oracle
    • statement
    • function
    • clause
    • plsql
    • sql
You are here: Home / Oracle / statement / SQL SELECT Statement

SQL SELECT Statement

October 22, 2012 by techhoneyadmin

SQL SELECT StatementThe SQL SELECT Statement allows us to retrieve or fetch records from one or more (by using Oracle SQL Joins) tables from our database.


SQL SELECT Statement Syntax

SELECT column(s)
FROM table_name(s)
WHERE conditions;

SQL SELECT Statement Examples

Suppose we have a table named “Employee” with the data as shown below.

Employee_ID Employee_Name Salary Department Commission
101 Emp A 10000 Sales 10
102 Emp B 20000 IT 20
103 Emp C 28000 IT 20
104 Emp D 30000 Support
105 Emp E 32000 Sales 10

Now we will see what the SQL SELECT Statement does when used in different scenarios


SQL SELECT Statement – Using ‘*’ to view all records from a table

The SQL SELECT Statement can be used with the ‘*’ wildcard character to fetch all the columns and rows from a table.

For example, the below SQL SELECT Statement, once executed, will return all the data from the employee table.

SELECT *
FROM employee;

The result of the above SQL SELECT Statement query will be:

Employee_ID Employee_Name Salary Department Commission
101 Emp A 10000 Sales 10
102 Emp B 20000 IT 20
103 Emp C 28000 IT 20
104 Emp D 30000 Support
105 Emp E 32000 Sales 10

Again, in the above SQL SELECT Statement query, we have used the ‘*’ wildcard character to view all the records from the employee table.


SQL SELECT Statement – Selecting individual fields from a table

We can use the SQL SELECT Statement to select and view only certain fields from a table.

For example, the below SQL SELECT Statement query will return “employee_id”, “employee_name” and “department” fields only from the employee table.

SELECT employee_id
       ,employee_name
       ,department
FROM employee;

The result of the above SQL SELECT Statement query will be;

Employee_ID Employee_Name Department
101 Emp A Sales
102 Emp B IT
103 Emp C IT
104 Emp D Support
105 Emp E Sales

Here we can see that in the SQL SELECT Statement we have explicitly mentioned that we wish to see only the “employee_id”, “employee_name” and “department” columns from the employee table.


SQL SELECT Statement – Using WHERE Clause

The SQL SELECT Statement can be used with the SQL WHERE Clause to filter records based on requirements.

For example, the below SQL SELECT Statement will return “employee_name” and “Salary” of employees working in “Sales” department from the employee table.

SELECT employee_name
       ,salary
FROM employee
WHERE department='Sales';

The data returned by the above SQL SELECT Statement will be:

Employee_Name Salary
EMP A 10000
EMP E 32000

The column names after the SQL SELECT Statement mentions that we want to view the data only for “Employee_Name” and “Salary” columns for “Sales” department only from employee table.


SQL SELECT Statement – Selecting fields from several tables

The SQL SELECT Statement can fetch columns from many tables at once.

For example,

SELECT orders.order_id
       ,suppliers.supplier_name
FROM suppliers
    ,orders
WHERE suppliers.supplier_id = orders.supplier_id;

The above SQL SELECT Statement joins two database tables namely “Orders” and “Suppliers” and returns us the result based in condition that the value for “Supplier_Id” field is available in both the joined tables.

Learn more about Oracle SQL Joins.


Filed Under: statement Tagged With: how to use select statement in oracle database query, how to use select statement in oracle plsql, how to use select statement in oracle sql, select statement in oracle plsql, select statement in oracle sql, SELECTSTATEMENTPLSQL, syntax and example of select statement in oracle database query, syntax and example of select statement in oracle plsql, syntax and example of select statement in oracle sql, using select statement in oracle database query, using select statement in oracle plsql, using select statement in oracle sql

Copyright © 2023 · Parallax Pro on Genesis Framework · WordPress · Log in