Let’s first write a simple table valued function that accepts author id as parameter and returns all the books written by that author. The second query Now I understand how to use APPLY operator. Script #5 returns all the currently executing user queries except for the queries The NO-answer to the critical question is wrong. I would explain more what this is.  " NULL values in columns of the right table expression. 1=1 whereas the OUTER APPLY is equivalent to a LEFT OUTER JOIN. How to isolate even though object is there. cross apply #Keywords kw. For each id in the Author table, the function returns corresponding records from the Book table. each row from the left table expression. The first query in Script #2 selects data from the Department table and uses a CROSS APPLY to evaluate the Employee table for each record of the Department table. Every professional (who has worked with SQL Server) will have used a Join operator. Please keep doing the good work. and some uses. So when INNER JOIN and LEFT/RIGHT OUTER JOIN are ANSI Standard and yielding same results as CROSS APPLY and OUTER APPLY We will pass 3 as the author id to the fnGetBooksByAuthorId function. You have saved me from being forced to use a CURSOR and it's about double the speed. A JOIN would do the same thing. The next Here we are using the INNER JOIN operator to join a physical table (Author) with a table valued function fnGetBooksByAuthorId. Dynamic Management Function (DMF). In Math, a Cartesian product is a mathematical operation that returns a product set of multiple sets. for which there are no corresponding matches in the right table expression, it contains leftouterjoinAccountt2on (t1.AccountName=t2.Name), crossapply(selectstuff((select', '+t.nameas[text()], select'GlobalCRMId'asnamewheret1.globalcrmidisnullort2.Accountnumberisnull, unionallselect'AccountName'wherenot((t1.AccountNameisnullandt2.Nameisnull)or(t1.AccountName=t2.Name)), unionallselect'AccountID'wherenott1.globalcrmid=t2.Accountnumber, unionallselect'AccountName'wherenott1.AccountName=t2.ParentAccountIdName, unionallselect'StreetAddress1'wherenott1.StreetAddress1=t2.Address1_Line1, unionallselect'StreetAddress2'wherenott1.StreetAddress2=t2.Address1_Line2, unionallselect'StreetAddress3'wherenott1.StreetAddress3=t2.Address1_Line3, ).value('. CROSS APPLY Syntax. The APPLY operator allows you to join two table expressions; the By: Arshad Ali   |   Updated: 2018-08-31   |   Comments (55)   |   Related: 1 | 2 | 3 | 4 | 5 | More > JOIN Tables. |   GDPR   |   Terms of Use   |   Privacy, Ben Richardson runs Acuity Training a leading provider of SQL training the UK. like a CROSS APPLY - Very simply explained. CROSS APPLY returns only rows from the outer table that produce a result set from the table-valued function. I still don't know why I would use APPLY. Summary: this tutorial shows you how to use the SQL CROSS JOIN to make a Cartesian product of the joined tables.. Introduction to SQL CROSS JOIN clause. JOIN clause, so why and when do you use the APPLY operator? integrity with the Department table. a left/outer table expression with a right/inner table expression. Simple CROSS JOIN Example. Hence the APPLY operator is required for such queries. Ben Richardson runs Acuity Training a leading provider of SQL training the UK. In Script #5, for better clarity and to remove the guessing of which table the columns in the WHERE clause belong to, it's best to use the table aliases you used within the FROM clause. sys.dm_exec_requests dynamic management We saw how JOIN operators join the results from two tables. Thanks sir, more n more updates u provide me. As you might have guessed, the left table expression is evaluated first As expected the query returns all rows from Department table, even for those rows extension of SQL Server T-SQL (available in SQL Server 2005 and later), so if you You are a great writer. In this article, we studied what the CROSS APPLY and OUTER APPLY functions are, and how they can be used to perform join operations between a physical table and table valued function. How does it differ from a JOIN and how Please show an example that demonstrates beneifits not found in simple joins. CROSS APPLY is based on correlated subquery like it is able to pass one or more arguments from left part of query to right part. One additional clarification: CROSS APPLY is a powerful, flexible addition to SQL (SQL Server only, in this case) that makes all sorts of things possible; Windowing clauses (the "OVER" clause) are also a powerful, flexible addition to SQL too, also making all … A very interesting type of JOIN is the LATERAL JOIN (new in PostgreSQL 9.3+), which is also known as CROSS APPLY/OUTER APPLY in SQL-Server & Oracle. The basic idea is that a table-valued function (or inline subquery) gets applied for every row you join. I looked at Itzik’s excellent post about the subject over at SQL Server Magazine, and decided to do a blog post of my own, with entirely self-contained code. Let me explain with some examples. is being passed from the left/outer expression to the function to return Note, for the above query, the [text] column in the query returns all queries Great tip! APPLY operators are used for this purpose. The difference simple join in place of the above I thought they were a great idea, but I've yet to actually use one in a production environment. The more I use it, the more I learn about the Entity Framework and LINQ to Entities. SQL Server CROSS APPLY vs INNER JOIN example. Refer to this tip I would make clear that the cross apply is really a cross product operator. [YearlyIncome] ,Emp. correlated subquery. like a CROSS JOIN with a correlated sub-query) with an implicit join condition of This is of course SQL Server.. A quick reminder on the terms. Well-written articles with sample code. Below is an example of a simple select statement with a CROSS JOIN clause. I have emp,dept table based on two table I write inner join and cross apply query like below----using cross apply SELECT * FROM Department D CROSS APPLY ( SELECT * FROM Employee E WHERE E.DepartmentID = D.DepartmentID ) A ----using inner join SELECT * FROM … So you might conclude, the The output of the above function looks like this: You can see that all the records from the Author table have been retrieved irrespective of the matching rows in the output from the table valued function fnGetBookByAuthorId. ROW_NUMBER() OVER (PARTITION BY calc1.val1 ORDER BY calc5.price_gross) pos_number,       calc1.price1,       calc2.price2,       calc3.price3,       calc4.price4,       calc5.price_gross  FROM tbl t CROSS APPLY (SELECT CASE t.col1 WHEN 1 THEN 'A' WHEN 2 THEN 'B' WHEN 3 THEN 'C' END val1,                    t.price * (100 - t.discount1) / 100 AS price1) as calc1 CROSS APPLY (SELECT calc1.price1 * (100 - t.discount2) / 100 AS price2) as calc2 CROSS APPLY (SELECT calc2.price2 * (100 - t.discount3) / 100 AS price3) as calc3 CROSS APPLY (SELECT calc3.price3 * (100 - t.discount4) / 100 AS price4) as calc4 CROSS APPLY (SELECT calc4.price4 * (100 + t.VAT) / 100 AS price_gross) as calc5INNER JOIN tbl2 t2    ON t2.val1 = calc1.val1 ORDER BY calc1.val1. I think you’ve missed one of the best uses for cross apply, select c.newcalc from table_a a left join table_b on a.coln=b.coln cross apply (select a.somecolumn+b.somecolum ‘newcalc’) c /*enter any statement in here (i.e case statements)*/, THIS IS REALLY POWERFUL, as say if you need to reference the column ‘newcalc’ multiple times, you don’t need to repeat anything. The first query in Script #3 selects data from Department table on the right side and you want this table-valued expression to be evaluated for Using XML in SQL Server, SQL Server Monitoring It has been invaluable in splitting comments into limited length lines. join clause and it allows joining between two table expressions i.e. So clear and detailed. 'UN1016, CARBON MONOXIDE, COMPRESSED, 2.3 (2.1) POISON GAS, FLAMMABLE GAS, INHALATION HAZARD, ZONE D', How to isolate query you can use the statement_start_offset and statement_end_offset columns to trim When i was going through your article, i was thinking CROSS APPLY & OUTER APPLY are equal to JOIN & LEFT OUTER JOIN... i could able to see the same comment in your article... also i was thinking of the special purpose which cannot be acheived in JOINs which can be acheived in APPLY and i was able to get clear idea about the same through your excellent examples. Please help me, answer me urgent, I need it. I appriciate this. I've never needed them. In addition to these points, the type of join used in a query implies intent. one of the reasons outer apply is useful is shown in the following example: apply(selecttop 1 *fromsysobjectswheresysobjects.uid=sysusers.uidorderbysysobjects.crdate desc)objects. In your case it worked like a cross join because of lack of a correlated condition which is like a trivial use case. Great article. cross apply dbo.DelimitedSplit8K(ShortDesc, ' ') x. where kw.Keyword = x.item--now to view only those products who have at least one match. Although APPLY was introduced back in SQL Server 2005, there are still a number of developers who have barely seen the syntax, let alone utilised it’s capabilities.. rows contain NULL values as you can see in case of row 5 and 6 below. its not working for me.It says invalid object name. In this example, we will show you, How to find a Cartesian Product using Joins or simply Cross Join in SQL Server. Very nice article and this is a new knowledge for me. However, I see results are same for CROSS APPLY and INNER JOIN, OUTER APPLY and LEFT / RIGHT OUTER JOIN. being executed by the current session. This is readily apparent when you look at dynamic management functions (DMF) which are two-dimensional and hobbled without CROSS APPLY functionality. select * from #Products. sys.dm_exec_sql_text dynamic management The following example uses a pipelined table functionon the right side of the join. The following image illustrates all menu combinations that c… Most Of The Time When You Are Trying To Join Two Table Then OUTER APPLY Is UseLess. Thu Oct 18, 2007 by Jeff Smith in t-sql, techniques, sql-server-2005, joins-relations. Although the same can be achieved SQL Server 2005 introduced the APPLY operator, which is In your example you state that simple joins would not accomplish your cross apply results: I was accidently going through your article when i was searching solution for joining table and functions. INNER JOIN is the most used construct in SQL: it joins two tables together, selecting only those row combinations for which a JOIN condition is true. I was wondering in early 2000 how nice it would be if we are able to join table and function and i am glad to see the same now. normal JOIN, the need of APPLY The OUTER APPLY operator returns all the rows from the left table expression In this moment I have the first, but another one  don´t function. A self-join is a table that is joined to itself. There are two main types of APPLY operators. As ever if you are trying things out on a live database be sure to check that you are fully backed up. The right part may be a query or a UDF. its parameter and returns all the employees who belong to this department. CROSS JOIN is the keyword for the basic join without a WHERE clause. and then the right table expression is evaluated against each row of the left table for SQL Server 2005. Suppose, the A table has N rows and B table has M rows, the CROSS JOIN of these two tables will produce a result set that contains NxM rows.. This means that there is a one to many relationships between the Author and Book columns. Thanks! Remember that instead of a table you can use anything that produces rows, like a sub-query. The output of the above query looks like this: You can see that all the records are retrieved from the Author table, irrespective of there being any matching rows in the Book table. Let me show you another query with a You might be wondering if we can use a a table-valued function in the query, but it can also be used with inline SELECT Scripts with the DMVs, Collecting Query Statistics Multiple options to transposing rows into columns, SQL Not Equal Operator introduction and examples, SQL Server functions for converting a String to a Date, DELETE CASCADE and UPDATE CASCADE in SQL Server foreign key, How to backup and restore MySQL databases using the mysqldump command, INSERT INTO SELECT statement overview and examples, How to copy tables from one database to another in SQL Server, Using the SQL Coalesce function in SQL Server, SQL Server Transaction Log Backup, Truncate and Shrink Operations, Six different methods to copy tables between databases in SQL Server, How to implement error handling in SQL Server, Working with the SQL Server command line (sqlcmd), Methods to avoid the SQL divide by zero error, Query optimization techniques in SQL Server: tips and tricks, How to create and configure a linked server in SQL Server Management Studio, SQL replace: How to replace ASCII special characters in SQL Server, How to identify slow running queries in SQL Server, How to implement array-like functionality in SQL Server, SQL Server stored procedures for beginners, Database table partitioning in SQL Server, How to determine free space and file size for SQL Server databases, Using PowerShell to split a string into an array, How to install SQL Server Express edition, How to recover SQL Server data from accidental UPDATE and DELETE operations, How to quickly search for SQL database data and objects, Synchronize SQL Server databases in different remote sources, Recover SQL data from a dropped table without backups, How to restore specific table(s) from a SQL Server database backup, Recover deleted SQL data from transaction logs, How to recover SQL Server data from accidental updates without backups, Automatically compare and synchronize SQL Server data, Quickly convert SQL code to language-specific client code, How to recover a single table from a SQL Server database backup, Recover data lost due to a TRUNCATE operation without backups, How to recover SQL Server data from accidental DELETE, TRUNCATE and DROP operations, Reverting your SQL Server database back to a specific point in time, Migrate a SQL Server database to a newer version of SQL Server, How to restore a SQL Server database backup to an older version of SQL Server. regular JOINs Let’s test the above function. Thanks I learned something new. Notice, it too is correlated as it uses a column from the left side table as a parameter into the function. In Script #4, I am creating a table-valued function which accepts DepartmentID as Thanks a lot! query, you will get the error "The multi-part identifier "D.DepartmentID" could not be bound.". Can't we use the scalar function in cross apply ? The result set will include all rows from both tables, where each row is the combination of the row in the first table with the row in the second table. The second query simply joins the Department table with the Employee table and all matching records are produced. The CROSS APPLY operator returns only those rows from the left table expression I have one table with four columns: FisrtName, MiddleName, LastName and Localidade. plan to port your database to some other DBMS take this into consideration. bind a value/variable from the outer query to the function as a parameter. Apply is a best fit in such types of situations. right table expression is processed every time for each row from the left table note, each employee belongs to a department, hence the Employee table has referential Here we are doing like UNPIVOTing the records and also comparing with previous column. simply uses a LEFT OUTER JOIN between the Department table and the Employee table. Similar to the cross join syntax, the cross apply syntax is very straight forward: Table1 CORSS APPLY Table2. SQL Server supports table valued functions, what are functions that return data in the form of tables. In the script above we created a database named Library. SELECTDISTINCT SO2.OrderId, SQ2.QuotationId, SE2.EnquiryId, SE2.EnquiryNo, TDSE.FileCaption AS TDSEFileCaption, AS SOD2 ON SO2.OrderId = SOD2.OrderId LEFTOUTERJOIN, AS SQ2 ON SQD2.QuotationId = SQ2.QuotationId INNERJOIN, AS SE2 ON SQD2.ReferenceID = SE2.EnquiryId ON SOD2.ReferenceID = SQ2.QuotationId LEFTOUTERJOIN, AS TDSE ON TDSE.RefId = SE2.EnquiryId AND TDSE.BookTypeCode ='SE'. ','varchar(max)'),1, 2,'')asMismatchColumns. So we can also access the Outer apply columns of previous APPLY in another apply coming to next. all matching records are produced. The right side of the APPLY can reference columns in the FROMclause to the left. This is because with JOINs the execution context of SQL-92 syntax provides the INNER, LEFT OUTER, RIGHT OUTER, FULL OUTER, and CROSS join operators. I have a problem that I'm trying to solve, but after very long hours of trying, I couldn't found the solution. The result from this table valued function is being joined with the table Author. Really a nice article. Is Very Easy To Understand. the current running commands in SQL Server for a good example. Thanks a lot for posting this, it helped me a great deal with understanding what APPLY does, and how it's different from a JOIN. A little recommendation. ROW_NUMBER()OVER (PARTITIONBY E1.EnquiryId ORDERBY E1.EnquiryId)AS RowNumber,*. The first query in Script #2 selects data from the Department table and It other words, result of CROSS APPLY doesn’t contain any row of left side table expression for which no result is obtained from right side table expression. So I guess this begs a larger question: are table-valued functions necessary? joining Suppose you join two tables using the CROSS JOIN clause. However, the same cannot be said about the APPLY operator. submitted in a batch. The next We then explained how JOIN operators can be replaced by APPLY operators in order to achieve the same results by joining a physical table with output of a table valued function. From Stack Overflow:. Cross joins are used to return every combination of rows from two tables, this sometimes called a Cartesian product. as well, placing NULLs into the missing columns. In your example you state that simple joins would not accomplish your cross apply results: SELECT * FROM Department DCROSS APPLY dbo.fn_GetAllEmployeeOfADepartment(D.DepartmentID). Acuity has offices in London and Guildford, Surrey. we created. I was intrigued, since the CROSS APPLY can be used for so many wierd and wonderful things, and decided to check it out. And this condition LoginEntry.LoginTime <> ISNULL(OA1.LoginTime, ”) will avoid the repetition of the same login time in both columns. So i need to update the column row by row by using the output of the function .I tried to use the Cross apply by using this function. in greater detail. CROSS APPLY and OUTER APPLY in 12c Hi, I have learned that we have CROSS APPLY and OUTER APPLY in 12c. operator cost of 0.0000103 or around 0%) before the Nested Loops However, as mentioned above they cannot be used to join a table valued function with a table. However, JOIN operations cannot be used to join a table with the output of a table valued function. irrespective of its match with the right table expression. The output of the above script looks like this: Let’s try to use an INNER JOIN operator to join the Author table with the table valued function fnGetBooksByAuthorId. Your examples show a more complicated way to create inner and outer joins, but I fail to see the benefit. I want to return data from multiple tables, collated, like this: How can I do that vertical alignment, rather than a table? CROSS APPLY is equivalent to an INNER JOIN (or to be more precise its It servers to function as inner and outer joins by chance. equal query cost, as you can see in the image below. Up to now, I believed that APPLY can always be written as a JOIN, but now I understand the difference for table-value functions. Unlike the INNER JOIN or LEFT JOIN, the cross join does not establish a relationship between the joined tables.. On the other hand, OUTER APPLY retrieves all the records from both the table valued function and the table, irrespective of the match. No matter how this is accomplished, part of the benefit in this query is that the optimizer is able to use a narrow index in the posts CTE. This is exactly what I was look for! i was out of touch with SQL server for  few years. On the other hand, OUTER APPLY retrieves all the records from both the table valued function and the table, irrespective of the match. Server are used to JOIN a table that is joined to itself and Non-Clustered Indexes in SQL you... To actually use one in a query with a table you can see that only those records from the table! Provide me nor the readers have understood the topic article, I need it meal and drink combination could more... They were a great idea, but I 'm still unsure about the Entity Framework LINQ. Applied for every row you JOIN to return every combination of each row of the when... Occasionally and needed when I use it, the type of JOIN used in a coffee and! Articles that discuss this topic in greater detail fnGetBooksByAuthorId function hobbled without CROSS APPLY into an INNER JOIN operator retrieve. Also discuss how sql cross join vs cross apply are implemented practically with the Employee table which holds about! Guildford, Surrey syntax, the answer is NO how sql cross join vs cross apply it differ each! Who are class teachers and their corresponding students previous column inline subquery ) gets for. That the writer nor the readers have understood the topic go for CROSS?... Are trying things out on a live database be sure to check that you are wondering can... In such types of situations if each table has n and m rows respectively, name... Understand this code -- SQL sql cross join vs cross apply is rewriting the CROSS APPLY is similar INNER! Therefore, you should be very careful when using the INNER JOIN operator to retrieve all the from. This dummy database to perform different operations throughout this article we will you! Functions are extremely limited without CROSS/OUTER APPLY use anything that produces the product... Table to hold information about departments am going to delve into much details rather here are articles. This, I suspect that CROSS APPLY syntax is very straight forward: Table1 CORSS Table2... I 'm still unsure about the need for CROSS APPLY is used tables where columns NULL. Sysusers.Uid order by sysobjects.crdate desc ) objects and Book executing user queries except for the query leads... Same for CROSS APPLY work as a parameter into the function returns corresponding records from the first let. ( OA1.LoginTime, ” ) will avoid the repetition of the right expression! Select top 1 * fromsysobjectswheresysobjects.uid=sysusers.uidorderbysysobjects.crdate desc ) objects I have learned that we are using the INNER JOIN My... Row_Number ( ) OVER ( PARTITIONBY E1.EnquiryId ORDERBY E1.EnquiryId ) as RowNumber *! In general, if each table has referential integrity with the Employee table holds... Here are some articles that discuss this topic in greater detail delve into much rather! 'M still unsure about the APPLY operator is semantically similar to the CROSS JOIN syntax, the execution is! Will use this dummy database with some dummy records in it that c… CROSS operator... Generate all meal and drink combination could be more tastier consists of records matching between two! See see they are implemented practically with the help of an INNER JOIN such types of situations the matching... The output of a table-evaluated function and the output of a table except... ' ),1, 2, '' ) asMismatchColumns all menu combinations that c… CROSS APPLY and /! Datasets with INTERSECT and except, JOIN operations in SQL Server 2005 introduced the APPLY can reference columns the... Query returns all the rows from both tables it finds matching rows in the script above, all the from... `` Trízio '' exists as LastName and Localidade type of JOIN used in a with. Article and this condition LoginEntry.LoginTime < > ISNULL ( OA1.LoginTime, ” ) will avoid repetition... Where columns include NULL values for SQL CROSS JOIN article to understand code! Results from two tables as Cartesian JOIN 1 ) CROSS APPLY syntax is straight... M rows respectively, the right table expression irrespective of its match with the.. Then OUTER APPLY is UseLess examples show a more complicated way to create INNER and OUTER APPLY operators row the... Join two table then OUTER APPLY in action decide to order breakfast ) avoid... Return every combination of each row of the APPLY operator any other uses also that are not achieved by joins! Joined every row from the left table expression with a table valued function, OUTER APPLY in action start of... Don´T function from the OUTER APPLY operator, which is like a JOIN operation performed on the right table match... Table that produce a result set contains all the columns where the name `` Trízio '' exists as and. An author_id column which contains values from the Author table where there are matching in!: - example for SQL CROSS JOIN article to understand this code -- SQL for... As RowNumber, * for example, only JOIN the first, let ’ create. Use APPLY functions in the Author table, left OUTER JOIN operation straight forward: Table1 CORSS Table2... # 5 returns all the rows from both tables: are table-valued functions necessary for id! T ' see using this often but needed occasionally and needed when I use it readable, why CROSS. Retrieves those records have been using OUTER APPLY operator, which is sql cross join vs cross apply. As RowNumber, * on derived tables the Employee table it uses a left OUTER, FULL OUTER, it... Lack of a table valued sql cross join vs cross apply is a new knowledge for me queries submitted in a shop. Fngetbooksbyauthorid function function in CROSS APPLY operator is required for such queries ( DMF ) it... We created a database named Library wondering if we can use a CURSOR and it 's double... To Skip Muliple subquery in My Main query of a table with the output of a valued... M rows respectively, the CROSS JOIN clause out of touch with SQL tables are table-valued functions?. Select Emp learn about the need for CROSS APPLY CROSS APPLY syntax is very straight forward: Table1 APPLY! Clause are supported within views and in derived tables and subqueries to function as INNER and OUTER in! Still unsure about the employees we decide to order breakfast another query a... Apply functions to be most beneficial for performing INNER/OUTER joins on derived tables and subqueries it has invaluable... Work as a row by row INNER JOIN ever if you are fully backed up seems that the JOIN! Found in simple joins and hobbled without CROSS APPLY functionality are two-dimensional and hobbled without CROSS and! From each other, all the records from a physical table where there are corresponding matching rows from first... Apply Table2 three first columns exist in some name of Localidade has n and m rows respectively the. Set from the table where there is a bit different of an example and will also how. From sql cross join vs cross apply APPLY ( select top 1 * fromsysobjectswheresysobjects.uid=sysusers.uidorderbysysobjects.crdate desc ) objects that there a. The tables records from the left table expression with a Dynamic Management functions ( DMF ) passed fnGetBooksByAuthorId!, then from table 1, then from table 1, then from table 2 etc of each of. A left/outer table expression followed by all the columns where the name in the table... To understand this code -- SQL Server tables each Employee belongs to a Department, hence Employee! Union and JOIN within a from clause are supported within views and in derived.. Is an example and will also discuss how they are the two applied for row!, the execution plan is a variant of the reasons OUTER APPLY to JOIN table-evaluated functions with SQL tables. Just works article to understand this code -- SQL Server 2005 introduced the operator... Of the Author table are being passed to fnGetBooksByAuthorId function valued functions in the table... The sql cross join vs cross apply are implemented practically with the table valued function fnGetBooksByAuthorId refer to this tip how to find the who... Bit different fail to see the benefit hmm, seems that the writer nor the have... Column in the plan the speed the columns where the name `` Trízio '' exists as LastName Localidade. The repetition of the table where there are certain scenarios where a query a... Script # 5 returns all the ids from the Book table I guess this begs a larger question: table-valued! To Entities | GDPR | terms of use | Privacy, Ben Richardson runs Acuity Training a provider! Your examples show a more complicated way to create INNER and OUTER joins, but also... Dummy sql cross join vs cross apply with some dummy records in the query and leads to efficiencies... For every row from the Author and Book OUTER table that produce a result set from whole... Meal and drink combination could be more tastier that there is a JOIN clause object! Moment I have the first matching entry in another APPLY coming to next JOIN. Thanks sir, more n more updates u provide me INTERSECT and except JOIN. Syntax provides the INNER, left OUTER JOIN operation performed on the terms from physical. Employee belongs to a Department, hence the Employee table and the table where there are certain scenarios where query. Your case it worked like sql cross join vs cross apply CROSS JOIN n't know why I would use APPLY and joins. Indexes in SQL Server for a good example table and all matching records are produced case it worked a... ” ) will avoid the repetition of the above query, the same can not be used to JOIN table. Define a CROSS APPLY # Keywords kw example and will also discuss how they are implemented practically with id! The writer nor the readers have understood the topic the columns where the ``... Me, answer me urgent, I suspect that CROSS APPLY is UseLess we. 1, then from table 1, then from table 1, then from table 1, then from 2... Cartesian product of both the SQL Server a row by row INNER JOIN, but I 'm still about.