Thursday, 9 January 2014

SQL - QTP Interview Questions and Answers

Hello friends,
In this article I am going to discuss some questions based on sql queries. We will see some queries that are frequently asked in QTP Interviews.

1. SQL Query to find the second highest salary of the employee

This query is very popular among interviewers. Answer is also very simple
select max(salary) from emp where salary not in (select max(salary) from emp)

As you can see, we have used nested query to get the second highest salary of the employee. But above query can not be generalised to find the nth max salary.
Below code will solve the issue easily.
Select min(salary) from (select top 2 distinct salary from emp order by salary desc)  

Above query will get the second highest salary. To get the nth highest salary, you have to just replace 2 by n.
So the query to get the 4th highest salary will be 
Select min(salary) from (select top 4 distinct salary from emp order by salary desc)  

Please note that above query works in sql server and microsoft access but not in other databases like oracle or mysql.

2. SQL Query to find the duplicate values from the column.

Sometimes we need to find the duplicate values from the given column.
select city, count(city) from table group by city having count(city) > 1
Above query will print all cities that have appeared more than twice in the column city.

3. SQL Query to find the employees whose names start with s.

select * from emp where name like 's%'

To get the employees whose names start with s, a or b

select * from emp where name like '[sab]%'

4. SQL Query to copy records from one table to another.

select * into newtable from emp
Above query will copy all records from emp table to newtable.

To insert records in the existing table, you can use below queries.

insert into table1
select * from table2

insert into table1(name, city)
select name, city from table2.

5. How to execute the stored procedure in QTP?


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.