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.This query:
SELECT * FROM table1 JOIN table2 ON table2.b = table1.a
reads:
For each row fromNote that this condition can be rewritten as this:table1, select all rows fromtable2where the value of fieldbis equal to that of fielda
CROSS APPLY is a Microsoft's extension to SQL, which was originally intended to be used with table-valued functions (TVF's).The query above would look like this:
SELECT * FROM table1 CROSS APPLY( SELECT TOP (table1.rowcount) *FROM table2ORDER BY Id) t2For each fromtable1, select firsttable1.rowcountrows fromtable2ordered byid
0 Comments