SELECT query in Oracle

ORACLE SELECT
To fetch records from the tables and views stored in the database, the Oracle SELECT statement is used.

Syntax: To select all fields from a table.

SELECT * FROM table_name;  

Parameters:
table_name: It is used to specify the name of the table from which you want to retrieve the records.
Example: Selecting all fields from a table.

SELECT * from students;

Output:

STUDENT_ID STUDENT_NAME STUDENT_AGE
1 Joy 5
2 Smiley 13
3 Happy 11

Syntax: To select specific fields from a table.

SELECT expressions  
FROM table_name
WHERE conditions;   

Parameters:
expressions: It is used to specify the columns or calculations to be retrieved.
table_name: It is used to specify the name of the table from which you want to retrieve the records.
conditions: It is used to specify the conditions to be strictly followed for selection.

Example: Selecting specific fields from a table.

SELECT name, age  
FROM students  
WHERE  age > 10  
ORDER BY name;

Output:

STUDENT_ID STUDENT_NAME STUDENT_AGE
3 Happy 11
2 Smiley 13

Syntax: To select specific fields from multiple tables.

SELECT expressions  
FROM table1
INNER JOIN table2 
ON join_predicate;

Parameters:
expressions: It is used to specify the columns or calculations to be retrieved.
table1: It is used to specify the name of the first table from which you want to retrieve the records.
table2: It is used to specify the name of the second table from which you want to retrieve the records.
join_predicate: It is used to specify the condition for joining tables.

Example: Selecting specific fields from multiple tables.

SELECT students.name, teachers.subject
FROM students  
INNER JOIN teachers  
ON students.student_id = student_id  
ORDER BY name;

Output:

NAME SUBJECT
Happy English
Happy Hindi
Joy English
Joy Hindi
Smiley English
Smiley Hindi