Retrieving Data
SELECT
clause is used to retrieve rows from a table. Database The database consists of a
player
table that stores the details of players who are a part of a tournament.player
table stores the name, age and score of players.Let's explore more about the SELECT clause using the database!
Selecting Specific Columns
To retrieve the data of only specific columns from a table, add the respective column names in the SELECT clause.
Syntax
SQL
Example
Let's fetch the
name
andage
of the players from theplayer
table.SQL
Output
name | age |
---|---|
Virat | 32 |
Rakesh | 39 |
Sai | 47 |
--- | --- |
Selecting All Columns
Sometimes, we may want to select all the columns from a table. Typing out every column name, for every time we have to retrive the data, would be a pain. We have a shortcut for this!
Syntax
SQL
Example
Get all the data of players from the
player
table.SQL
Output
name | age | score |
---|---|---|
Virat | 32 | 50 |
Rakesh | 39 | 35 |
Sai | 47 | 30 |
--- | --- | --- |
Selecting Specific Rows
We use WHERE clause to retrieve only specific rows.
Syntax
SQL
WHERE
clause specifies a condition that has to be satisfied for retrieving the data from a database.Example
Get
name
andage
of the player whosename
is "Ram" from theplayer
table.SQL
Output
name | age | score |
---|---|---|
Sai | 47 | 30 |
Try it Yourself!!
The database consists of an
employee
table that stores theemployee_id
,name
andsalary
of employees.
Let's fetch data for the following queries.- Get all the data from theemployeetable.
- Getnameandsalaryof all the employees from theemployeetable.
- Getemployee_idandsalarywhosenameis "Raju" from theemployeetable.