 Hello, welcome to SSUnitech. So, see this side and this is continuation of SQL Server interview questions and answers. So, this is part two top 20 SQL queries interview questions and answers for the beginners. So, let's start with our first question. So, write a query to get all the rows from employees table. So, here we have to use select star from employees which is our table name. Once we gonna use star then it will pick all the columns which is available in employees table. So, it will get all the rows with all the columns. Move to next question. So, write a query to find total number of rows in employees table. So, here we have to use our inbuilt function which is count. So, we have to use select then count inside the bracket we need to specify star from employees which is our table name. Move to next question. So, write a query to remove duplicate rows in a result set. So, here we have to use distinct keyword. So, it is used to remove the duplicate rows which is present in our table. So, our query would be select distinct star from employees which is our table. Move to next question. So, write a query to display all the records in employee table where employee belongs to department number 5. So, here we have to use select star from employees where we need to specify department number should be equals to 5. So, here we gonna use where condition. So, it will filter the result set with department number 5. Move to next question. So, write a query to display all the records in employee table with salary decreasing order. So, here we have to specify select employee ID employee name salary department ID or we can use star then from employees which is our table then we have to use order by clause. So, here we have to specify order by salary in our decreasing order. Here we have two options. First for ascending, second is descending. So, here we gonna use in descending order. Move to next question. Write a query to display first 5 records in employee table. So, here we gonna use top keyword. So, our query would be select top 5 star from employees. So, it will get top 5 rows from employee table. Move to next question. So, write a query to display all the employees who were joined in year 2018. So, here we have to use a function which is our year function. So, it will get the year part from our date and time. So, we have a column with date of joining in our employee table. Our query would be select star from employees where we gonna fetch year from date of joining and that year should be equals to 2018. So, it will reflect those rows who were joined in year 2018. Move to next question. So, write a query to display all the employees who were joined first quarter of the 2018. So, here our query would be select star from employees where date of joining should be between 2018 01 01 which is our first day of quarter one and 2018 03 31 which is last day of our quarter first. Move to next question. So, write a query to concatenate first name, middle name and last name to get full name in employee table. So, here we gonna use select first name then concatenate symbol that is plus then we gonna put an space then again plus our middle name then plus put some space then plus last name. It will combine first name then space middle name space our last name and it will reflect as a full name from employee table. Move to next question. So, write a query to fetch the records which first name is Rajesh. So, here we gonna use select a stick from employees where first name should be equals to Rajesh and Rajesh is in single quit because our first name is work at data type. Move to next question. So, write a query to fetch the records which first name starts with R. So, here we have to use like operator with wild card characters. So, under score will be used for the single character and percentile will be used for the multiple character. So, here we gonna use select a stick from employees where first name like we need to specify R then percentile and it would be inside a single quit. So, move to next question. So, write a query to fetch the records which first name starts with R and end with H. So, here again we gonna use our wild card characters with like operator. So, our query would be select a stick from employees where first name like R then percentile because between R and H it would be many character that's why we wanna use percentile. Then our last character would be H and this value will be inside a single quit. Move to next question. So, write a query to fetch the records which first name should have three characters. So, as I have discussed for single character we need to use underscore and for multiple character we have to use percentile. So, here in this query as you can see select a stick from employees where first name like we have three underscores. So, it should have three characters. Then we gonna use percentile. So, percentile will be reflecting multiple characters. So, it should have at least three characters because we have specified three underscores. Move to next question. Write a query to fetch those records which first name second position is A. So, here again we gonna use select a stick from employees where first name like then our first character would be anything. So, we gonna use underscore then our second character must be A. So, we have to specify A. After that our character would be anything that's why we gonna use percentile. Move to next question. So, write a query to fetch those records which first name starts with A or M or F. Once we get such type of scenarios then we have to use this query. Select a stick from employees where first name should be like then inside the bracket we have to specify those characters which may be our starting characters like A or M or F and we gonna put in a bracket and our next character would be anything and we don't know the length that's why we gonna use percentile. Move to next question. Write a query to fetch those records which first name starts between A to F. Once we get such type of scenarios then we have to use this query. Select a stick from employees where first name like then again inside a bracket we have to specify those characters like A to F so we have to use A then minus F and this value should be in our bracket and then we gonna use percentile. So, this is our query. Move to next question. So, write a query to fetch the records which first name has wildcard character percentile or underscore. So, once we get such type of scenario then we can use select a stick from employees where first name like then we have to specify percentile inside the bracket. Again we have to specify percentile then again we have to specify percentile without a bracket. So, it will reflect first name should contain percentile and it may be contain at any position. That's why we have to specify percentile at starting and at end. And we have to our condition like it may be percentile or underscore. So, we have to use our condition with first name like and we need to check for the underscore. So, this is our query. Move to next question. Write a query to fetch first four characters of the field first name from the table employees. So, here we have two options. First, we can use left function. Second, we can use sub string function. So, in our first query as we can see we gonna use left function. So, select left then we need to start bracket then first name then we need to specify comma then how many characters we want. We need to specify over here. So, that would be four. Close the bracket from our employees table. So, this is our first query. In our second query we gonna use sub string function. So, select sub string then we need to specify the column name which is our first name then we need to put comma then our starting position that would be one then how many characters we want. We need to specify in our third parameter that is four. So, close the bracket from employees table. So, these two queries will return the output as we are expecting. Move to next question. So, write a query to insert first name into employees table with single query. So, here we have two options to insert record in our employees table. In our first query as you can see select into employees then we need to specify values then inside the bracket we have to use our single query then our value then we have to specify three single queries. In our second query as we can see insert into employees select we need to specify triple single query then our name then our single query. So, our double single query will be treated as a single and it will be included with our name. Move to next question and this is our last question. So, write a query to get the name of the SQL Server instance. So, here we have a global variable that is at the rate at the rate server name. So, it will return name of SQL Server instance. So, thank you so much for watching this video. If you like this video please subscribe our channel to get many more videos. Don't forget to press the bell icon to get the notification of our newly uploaded videos. Thank you so much.