How Can We Help?
Introduction:
SQL SELECT statement is used to fetch the data from a database table.
In Oracle, tables are consists of columns and rows. For example, the suppliers table in the sample database has the following columns: supplier_id, name and address. The suppliers table also has data in these columns.
Syntax:
SQL SELECT statement is used to fetch the data from a database table like “Suppliers” table which returns this data in the form of a result table. These result tables are called result-sets.
To retrieve data from one or more columns of a table, you use the SELECT statement with the following basic syntax:
SELECT column_1
,column_2
,columnN
FROM table_name;
In this SELECT statement:
- First, indicate the columns from which you want to return the data. If you have more than one column, you need to separate each by a comma (,).
- Second, specify the table name from which you want to query the data.
Note that the SELECT statement is very complex that consists of many clauses such as ORDER BY, GROUP BY, HAVING, JOIN. To make it simple, in this tutorial, we are focusing on the SELECT and FROM clauses only.
If you want to fetch all the fields of the CUSTOMERS table, then you should use the following query.
SELECT * FROM SUPPLIERS;
The result set for this query would be like this:
– Query data from a single column
To get the supplier Company names from the suppliers table, you use the following statement:
SELECT company_name FROM suppliers;
here is the result:
– Querying data from all columns of a table
The following example retrieves all rows from all columns of the customers table:
SELECT supplier_id,
company_name,
contact_name,
address
FROM suppliers;
Here is the result:
In this tutorial, you have learned how to use Oracle SELECT statement to retrieve data from one or more columns of a table.