Oracle SQL Queries Interview Questions and Answers for Experienced
In this post we will discuss Oracle Sql Queries Interview Questions and Answers for Experienced. Queries part of Sql have more importance than any other part of Sql. So we have decided to publish the post Oracle Sql Queries Interview Questions and Answers for Experienced. We will discuss about Select from where clause, Use of like in sql example, Use of Between in Queries ,Use of Not Between , Use of Not Like in Queries in this post.
Queries are the most important part of any database system. We store records in database, so that we can use these records in future. This part of SQL is of much importance than other parts of SQL. In this part of SQL, the user learns to query database records. Before using queries, that tables must exist in database, for which you are going to write queries.
To query rows or records from database, the select from where clause is used.
Select from where clause
The General Syntax of Select From Where clause is as given below-
Select from where
Here Select is the keyword , after select we have to mention that columns of the database table, which are required in output. From is also a keyword , after keyword from we have to mention the name of the database table. Where is also a keyword , where is used to provide condition in queries. Where is optional , when there is no condition.
Example Suppose the query is “Give records of all the employees”.
The SQL statement will be like this:
The SQL statement will be like this:
Select * from employee;
This will list all the records of table employee.
This is basic of all the queries.
Let us take some more examples of queries
Query : Give name of all the employees.
Solution : Select ename from employee;
This will list the names of all the employees in employee table;
Query :Give name and city of all the employee.
Solution : select ename, ecity from employee;
Query : Give code, name and city of all the employee.
Solution : select ecode, ename ,ecity from employee;
Use of Where in queries
In select statements ,where is optional keyword. All the above queries were solved without where clause. But we can not do much without where clause. Where is useful for giving condition in select statement.
Suppose the query is “Give name of all the employees whose city is Melbourne “.
The select statement for the above query will be like this.
Select ename from employee where ecity =”Melbourne”;
Some more examples on queries
- Give name of all the employees
- Give name and salary of all the employees
- Give code ,name and salary of all the employees whose salary is greater than 50000
- Give code and name of all the employees whose city is Melbourne and salary is greater than 50000
- Give code and name of all the employees whose salary is between 50000 and 60000
- Give code and name of all the employees whose salary is not between 50000 and 60000
- Give code and name of all the employees whose city starts from letter M
- Give code and name of all the employees whose city does not start with letter M
Use of Between in Queries
Between is used in some particular type of queries. Between is used when we have to select records between two values.
Suppose the query is “Give records of all the employees whose salary is between 50000 and 60000.
Solution : Select * from employee where salary between 50000 and 60000;
Use of Not Between
Not Between is used in some how like between.
Suppose the query is “ Give records of all the employees whose salary is not between 50000 and 60000.
Solution : Select * from employee where salary not between 50000 and 60000;
Use of Like in Queries
Like is used for pattern matching in SQL.
Suppose the query is "Give name of all the employee whose name starts with capital letter 'A'
Solution : select ename from employee where ename like 'A%'
This will list names of all the employees whose name starts with capital letter 'A'. e.g. Anil, Amit etc.
Use of Not Like in Queries
Not like is complement of like. Suppose the query is to give name of all the employees whose name does not starts with capital letter 'A'
Solution : select ename from employee where ename not like 'A%'
This will list names of all the employees whose name does not starts with capital letter 'A'. e.g. Sunil, Vishal, Gagan etc.
Use of like in sql example
Use of Between in Queries
Use of Not Between
Use of Not Like in Queries