Some basic SQL queries which should be practiced before going to Interview - Part 1

Amatya
Posted by in Sql Server category on for Beginner level | Points: 250 | Views : 3300 red flag
Rating: 5 out of 5  
 1 vote(s)

Some SQL Server queries which you should prepare before going to your
interview. Basically while going to C#, ASP .Net interview SQL Server interview is common. So be prepare for SQL server
queries.

Introduction

Some basic SQL queries which should be practiced before going to Interview - Part 1

Describe the topic with code snippets

Hi guys, in this article I will talk about some SQL Server queries which you should prepare before going to your
interview. Basically while going to C#, ASP .Net interview SQL Server interview is common. So be prepare for SQL server 
queries. Here we go- 

1) Get employee details from tblEmp table whose employee name is "Amatya"

Select * from tblEmp where F_Name='Amatya'

2)Get employee details from tblEmp table whose employee name are "Amatya" and "Aditya"

Select * from tblEmp where F_Name in ('Amatya','Aditya')

3)Get employee details from tblEmp table whose employee name are not "Amatya" and "Aditya"

Select * from tblEmp where F_Name not in ('Amatya','Aditya')

4)  Get employee details from tblEmp table whose first name ends with 'u'

Select * from tblEmp where FIRST_NAME like '%u'

5)  Get employee details from tblEmp table whose salary is greater than 500000

Select * from tblEmp where Sal >500000

6) Count of number of employees in  department  wise.

select count(EMPNO), b.deptno, dname from tblEmp a, tbldept b  where a.deptno=b.deptno  group by b.deptno,dname;

7) Get unique department from tblEmp table

select distinct department from EMPLOYEE

8) How to delete duplicate rows in a table?

Delete from tblEmp a where rowid != (select max(rowid) from emp b where  a.empno=b.empno);

9)   Get employee details from tblEmp table whose joining year is “2017”

 
  Select * from tblEmp where SUBSTRING(convert(varchar,Work_Date,103),7,4)='2017'

10)  The || (double pipe) symbol concatenates two strings. 

 
SELECT F_Name || L_Name FullName
                              FROM tblEmp;
10 a)  Two column concatenated with comma seperate
                              SELECT L_Name || ',' || F_Name NAME
                                FROM tblEmp;
Hope it will help you guys in your preparation.






Conclusion

As soon as possible I will deliver more part of SQL Server queries to you all guys
All the Best. Stay blessed.
 Your opinion and suggestion are welcome.

Reference

From my notebook and learning experience

Page copy protected against web site content infringement by Copyscape

About the Author

Amatya
Full Name: Amatya Agyey
Member Level: Silver
Member Status: Member
Member Since: 5/9/2015 12:56:12 AM
Country: India
Feel free to share informations. mail Id ' adityagupta200@gmail.com Thanks
http://www.dotnetfunda.com
Software Enginner

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)