3. SELECT Command
While using Oracle when we need to extract information regarding data from the database, we use the SELECT statement. Using the SELECT statement, we can retrieve data from one column, multiple columns and all columns from a table. The asterisk can be used to SELECT all columns of a table. Before writing a SELECT statement, we must determine which table or tables contain the information that we need from the database.
Syntax
Select Column_name
FROM table_name;
Example
1. The following is a sample of a Select statement retrieving information from a single column.
Syntax (same as Select)
Select Column_name
FROM table_name;
Example
Assume the following STUDENT table.
| Stud_ID | Stud_Name | Age | Subject |
| 1001 | Mira | 17 | Oracle |
| 1002 | Ipshita | 19 | Oracle |
| 1003 | Aayushi | 18 | Unix |
| 1004 | Anjali | 19 | Database |
| 1005 | Swati | 20 | Unix |
Query
Select Stud_name
FROM Students;
Result
|
Stud_Name |
| Mira |
| Ipshita |
| Aayushi |
| Anjali |
| Swati |
2. The following is a sample of a Select statement retrieving information from Multiple columns.
Syntax
Select Column1, column2, column3
FROM table_name;
Example
Assume the following CUSTOMERS table.
| Cust_ID | Cust_Name | ContactNo | Location |
| 111 | Mira | 475617 | Kanpur |
| 222 | Ipshita | 845648 | Lucknow |
| 333 | Aayushi | 874875 | Amritsar |
| 444 | Anjali | 896575 | Mumbai |
| 555 | Swati | 939575 | Delhi |
Query
SELECT Cust_Name, Location
FROM Customers;
Result
| Cust_Name | Location |
| Mira | Kanpur |
| Ipshita | Lucknow |
| Aayushi | Amritsar |
| Anjali | Mumbai |
| Swati | Delhi |
3. The following is a sample of a Select statement retrieving information from all columns.
Syntax
Select *
FROM table_name;
Example
Assume the following EMPLOYEES table.
| Emp_Id | Emp _Firstname | Emp _Lastname | Age | Designation | Hire_Date |
| 00011234 | Ankit | Singh | 52 | Project Manager | 20th Oct' 1999 |
| 00011247 | Mohit | Chauhan | 43 | Projeact Lead | 15th Apr' 2003 |
| 00011239 | Karan | Sagu | 51 | Sr. Software Engg. | 1st Jan' 2008 |
| 00011252 | Seema | Lambha | 32 | Software Engg. | 25th Jan' 2012 |
| 00011261 | Ritu | Bohra | 37 | Tech Lead | 10th Aug' 2005 |
Query
SELECT *
FROM Employees;
Result
| Emp_Id | Emp _Firstname | Emp _Lastname | Age | Designation | Hire_Date |
| 00011234 | Ankit | Singh | 52 | Project Manager | 20th Oct' 1999 |
| 00011247 | Mohit | Chauhan | 43 | Projeact Lead | 15th Apr' 2003 |
| 00011239 | Karan | Sagu | 51 | Sr. Software Engg. | 1st Jan' 2008 |
| 00011252 | Seema | Lambha | 32 | Software Engg. | 25th Jan' 2012 |
| 00011261 | Ritu | Bohra | 37 | Tech Lead | 10th Aug' 2005 |
We can use the SELECT with various other clauses like:
- INSERT
- HAVING
- GROUP BY
- WHERE
- SAMPLE
| Sub_ID | Sub_Name | Mark_Obt | Tot_Marks |
| 10 | Hindi | 150 | 200 |
| 20 | English | 140 | 200 |
| 30 | Science | 125 | 200 |
| 40 | Maths | 138 | 200 |
| 50 | S.Study | 110 | 200 |

Comments
Join the conversation! Your thoughts help the community grow.