---
title: "What is CROSS APPLY in SQL SERVER?"  
description: "What is CROSS APPLY in SQL SERVER?"  
author: "Revati S Misra"  
published: 2023-07-11  
updated: 2023-07-12  
canonical: https://www.mindstick.com/forum/159032/what-is-cross-apply-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# What is CROSS APPLY in SQL SERVER?

What is [CROSS APPLY](https://www.mindstick.com/forum/159033/when-should-i-use-cross-apply-over-inner-join) in [SQL SERVER](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server)?

## Replies

### Reply by Aryan Kumar

[Cross](https://www.mindstick.com/forum/33892/how-to-handle-cross-thread-exception-in-winforms) [apply](https://www.mindstick.com/articles/13148/discover-to-apply-make-up-like-a-professional-supermodel) in [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) is a type of join that returns all possible combinations of rows from two tables. It is similar to a Cartesian product, but it is more efficient because it only returns the rows that are actually present in the tables.

The syntax for cross apply in SQL Server is as follows:

SQL

```plaintext
SELECT *
FROM table1
CROSS APPLY table2;
```

For example, the following code will return all possible combinations of rows from the `Customers` table and the `Orders` table:

SQL

```plaintext
SELECT *
FROM Customers
CROSS APPLY Orders;
```

This code will return all rows from the `Customers` table, even if there are no matching rows in the `Orders` table.

The `CROSS APPLY` operator is often used in conjunction with a user-defined function (UDF). For example, the following code will return all customers and their orders, where the order date is greater than today's date:

SQL

```plaintext
CREATE FUNCTION GetOrdersByDate(@Date DATETIME)
RETURNS TABLE
AS
BEGIN
RETURN
SELECT Customers.CustomerID, Customers.Name, Orders.OrderID, Orders.OrderDate
FROM Customers
CROSS APPLY Orders
WHERE Orders.OrderDate > @Date;
END;
```

The `GetOrdersByDate` UDF takes a date as input and returns a table with the customer ID, name, order ID, and order date for all customers who have placed an order on or after the specified date.

The `CROSS APPLY` operator can be a powerful tool for combining data from two or more tables. However, it is important to use it carefully, as it can also return a large number of rows.


---

Original Source: https://www.mindstick.com/forum/159032/what-is-cross-apply-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
