 Hello, welcome to SSUnited. So, see this side and this is continuation of SQL Server interview questions and answers. So, today we are going to discuss two more interview questions and these questions were asked in Optum. So, here as we can see we have input table and it would have three columns. First is column 1, then column 2, then column 3 and in output we just want to get only column 1 and column 2. So, as we can see the first row, so it is coming from column 1 and column 2. Then in the second row it is coming from column 1 and column 3. So, here the results set will be combined as column 1, then column 2, then column 1, column 3, then column 1, column 2, column 1, column 3. So, how we can write the query for getting this output? So, let's move to SQL Server Management Studio where we will write the query for getting this output. So, as I am using SQL 2017, you may have another version of SQL Server but this query will work for all the versions. So, first of all I would like to execute the create table script to create the table. So, here command completed successfully. So, table is created successfully. Now, I just want to insert a record on this table so we can execute this insert statement. So, as we can see five rows are detected. So, data is loaded successfully into the table. Then I just want to execute the select statement to check the records. So, here as we can see we are getting the column 1, column 2 and column 3. But in the output as we seen first we want column 1, column 2, then column 1, then column 3 like this. So, here we can use the column 1, then column 2 and we can use the union all operator and then we can use select this time column 1 and column 3 and this is from column values table. Now, let me execute the query to check the output. So, as we can see we are getting the output like column 1 and column 2, then column 1 and column 3. But this is not in the sequence. So, for that we can use order by clause and this should be on column 1. Now, let me execute the query and we can check the output. So, as we can see we are getting 1, 2, then 1, 3, then 100, 300, 100, 200. So, this is the output currently we are getting. Let's move to next question. So, in the second question as we can see we have input table that would have only one column and it has 1, 1, 1, 3 times, then 2, 2 times, then 3, then 4, 2 times. But we want only distinct records from this input table. So, here we wanted distinct records without using distinct operator and CTE with row number. So, we don't want to use these two methods by which we can get the distinct records. So, what would be the next method by which we can get the distinct records? So, here we have a very simple method by which we can get the output. So, go to once equals to our management studio and here as we can see we have a table. Let me execute this create table script to create the table. So, as we can see table is created successfully. Then I just want to insert record on this table. So, we can execute the insert statement. So, as we can see eight rows affected. So, data have been loaded successfully into the table. Now, we can check the data from this table. So, as we can see we are getting 1, 3 times, 2, 2 times, 3 and 4, 2 times. But in the output we want distinct data. So, for that we can use union and we can copy the above query and paste after the union. Now, let me execute this query and we can check the output. So, as we can see we are getting the distinct records without using the distinct operator and CTE with row number. So, we can use this for getting the output. So, these are the questions which was asked in Optum. 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. And if you need this script it will be available on the description of this video. So, you can pop it from there. Thank you so much for watching the video.