Important Sql complex queries interview questions

Introduction: In this tutorial, I am going to explain the SQL complex queries which is asked in every interview questions. So let's start today's tutorial. So let's start SQL complex queries fo practice with answers.


Important Sql complex queries interview questions


1. To add new 
Alter table employee add gender varchar(5)

2.Drop a column
Alter table employee drop column gender

                       Some Ms. Sql commands with examples

3.Or operator  in SQL
SELECT * from employee where employeeid=or employeeid=1

4.IN function in SQL 
SELECT * from employee where employeeid in(2,3)

5. Find record Not in SQL table using  IN function
SELECT * from employee where employeeid not in (1,2)

6.Between function in SQL
SELECT * from employee where employeeid between 1 and 2

7.Select commands with order by clause
SELECT * from employee order by name 
SELECT * from employee order by name desc
SELECT * from employee order by name asc

8.Max Function
SELECT max(name) from employee
SELECT max(salary) from employee

9.Max Function
SELECT min(salary) from employee
SELECT min(name) from employee

10.Avg Function
SELECT AVG(salary) from emp

11.LEFT Function
SELECT LEFT('Manish',3)
Result:Man


12.RIGHT Function
SELECT RIGHT('Manish',3)
Result:ish

13.CHARINDEX Function- Is use to find the index(position) of any character
SELECT CHARINDEX('i','Manish')
Result:4

14.LEN Function- Is use to find the length of character
SELECT LEN('Manish')
Result:6


15.GETDATE ()
Returns a datetime data type which contains current system data and time: 2018-09-24 09:51:36.568.
SELECT GETDATE()

16.Use of AND Operator
SELECT * from employee where employeeid=2 and employeeid=5
SELECT * from employee where employeeid=2 and salary=600

17.Use of OR Operator
SELECT * from employee where employeeid=2 or employeeid=5
SELECT * from employee where employeeid=2 or salary=4000

18.Use of IN Operator
SELECT * from employee where employeeid in (2,5,8)

19.Use of Between Operator
SELECT * from employee where employeeid between 3 and 7

20.Use of WildCard Operator
SELECT * from employee where name not like 'a%'
SELECT * from employee where name like '%a'
SELECT * from employee where name like '%m%'
SELECT * from employee where name like '_a%'
SELECT * from employee where name like '%a_'
SELECT * from employee where name like '[a,b]%'
SELECT * from employee where name like '[a-p]%'

21.Use of SUBSTRING() Function
SELECT SUBSTRING('Mohan',1,3)
Result:Moh





Previous
Next Post »