SQL Select With Examples

SQL or Structured Query Language is all about storing, retrieving and manipulating data in the database. The most important aspect of SQL is retrieval of data from database. SQL Select statement is used to retrieve data from tables or views.

SQL Select Statement

SQL SELECT statement enables us to retrieve the data from the database. The result of SQL Select query is returned in tabular format knows as result set.

SQL Select Query Syntax

SQL Select Query has two syntaxes – one for retrieval of data from particular columns and other for retrieval of all the data that is available in the table.

Retrieval of Data from Particular Column
Please find below the syntax for retrieval of data from particular column(s) of a table.

In the syntax above, the column_name should be specified between the SELECT and FROM keywords. The column_name that is specified in the query should exist in the table.

Retrieval of Data from Complete Table

In the syntax above, data from all the columns of the table is retrieved.

Let’s us try to understand SQL SELECT query in more detail with some examples.

SQL Select Example

Let us consider the following Employee table for all the scenarios that we will discuss as part of the example.

SQL-Select-Query-Example-Table

  1. We want to retrieve name of all the employees who are younger than 25 years of age.

    Output:
  2. We want to retrieve all the detail of employees who are younger than 25 years of age.

    Output:

    EmpId EmpName EmpAge EmpSalary
    1 Amit 22 2000
    3 Jason 24 2750
  3. We want to retrieve all the details of employees who are younger than employees having salary equal to 3000.SQL SELECT can also be used inside other select as a sub-query. Above requirement requires using select inside a sub query.

    Output:
  4. sql-select-statement-example-sub-query

Reference: Oracle Documentation

By admin

Leave a Reply

%d bloggers like this: