 Hi there, this is Krishanth from Bytescout and in this video we will be going to learn about one of the T-SQL execution plan operator called MergeJoin. The MergeJoin is one of the physical operator that SQL Server uses in PoolJoin, LeftJoin or InnerJoin and provides an output that is generated by joining two sorted datasets. And if your input tables are large then MergeJoin is the fastest join operation but the MergeJoin requires both input tables to be sorted on the joining columns which are defined by the own close of the join predicate. So how it works? Well because each input is sorted the MergeJoin operator gets a row from the outer input table and compares them with the inner input table and if the matching row is found then return the records and if no matching row is found then obtain a new row from the smaller input table and this process repeats until all rows have been processed. Now let's see this MergeJoin operator in action. Now here for this demo we will again use the same query which we have used in the previous video of nested loop but here with a minor change in the where close. Now let me enable the execution plan and execute this query. Now if we look in the execution plan here we can see that our query is using a MergeJoin. So in this case the query optimizer decides to use a MergeJoin as both input tables are large in terms of rows and they are also pre-indexed or shorted on this column. So if I hover over the outer input table which is sales order header here we can see that the actual number of rows is 31,465 and if I hover over the input table then here the actual number of rows is more than 1 lakh. Now if we go into the message tab here you can see that both input tables are scanned only once as opposed to the eight scan which we have already shown in the previous demo of nested loop join. Now here in the execution plan you can see this compute scalar operator because we are selecting this line total column in the select statement which is a derived column and hence this operator is being used in this execution plan. Now if we go into the previous video query of nested loop and for this query if I try to force the MergeJoin by writing a merge forcefully over here and now if I execute both this query and in the execution plan we can see that the cost relative to this bage for this query is only 2% and for the MergeJoin the cost of the same query relative to this bage is 98%. So don't force the MergeJoin until and unless it is required in the specific scenario. Alright now in the next video we will be going to learn about the third physical operator called HashMatchJoin. So stay tuned with us.