SELECT Statement
Select statement is used to retrieve the data from the database.We use the key word SELECT.
Using the Select statement, we can choose the column(s)of the same table or different tables using the join and
also can select the number of the rows either same or different tables.
Syntax-
SELECT *|[DISTINCT]Column|expression [Alias]
From Table_Name;
SELECT -a list of columns
* -Select the all columns
DISTINCT-suppresses the duplicates
alias-alternate name of the column(s) that is/are used as the heading of that column(s).
Table_name-specifies the table names containing the column(s).
Example-
1.Write the query to select the all columns of the table employee.
Query- select * from employee;
Output-
Number of Records: 5
ID Name email address phone_number salary
1 sharat sarat@gmail.com Hyderabad 123456890 5000
2 Ajay ajay@gmail.com Hyderabad 16756890 51000
3 Amit amit@gmail.com Delhi 16756890 51000
4 Aman Aman@gmail.com Lucknow 26756890 51000
5 Hari Hari@gmail.com Lucknow 36756890 15000
2.Write the query to find the distinct address in the employee table.
Query- SELECT distinct address FROM employee
Output-
Number of Records: 3
address
Hyderabad
Delhi
Lucknow
3.Write the query to display the id,name and the yearly salary of the employees and also
label the column heading id as Employee_Id,name as Name and salary as Annual Salary.
Query- SELECT ID as Employee_Id, Name as "Name", salary*12 as "Annual salary" FROM employee;
Output-
Number of Records: 5
Employee_Id Name Annual salary
1 sharat 60000
2 Ajay 612000
3 Amit 612000
4 Aman 612000
5 Hari 180000
4.Write the query to display the id,name and the yearly salary of the employees whose annual salaries are greater 200000 and also
label the column heading id as Employee_Id,name as Name and salary as Annual_Salary.
Query-SELECT ID as Employee_Id, Name as "Name", salary*12 Annual_salary FROM employee where Annual_salary>200000;
Output-
Number of Records: 3
Employee_Id Name Annual_salary
2 Ajay 612000
3 Amit 612000
4 Aman 612000
No comments:
Post a Comment