---
title: "When should I use CROSS APPLY over INNER JOIN?"  
description: "When should I use CROSS APPLY over INNER JOIN?"  
author: "Revati S Misra"  
published: 2023-07-11  
updated: 2023-07-12  
canonical: https://www.mindstick.com/forum/159033/when-should-i-use-cross-apply-over-inner-join  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 3 minutes  

---

# When should I use CROSS APPLY over INNER JOIN?

When should I use [CROSS APPLY](https://www.mindstick.com/forum/159032/what-is-cross-apply-in-sql-server) over [INNER JOIN](https://www.mindstick.com/forum/33572/sql-inner-join-keyword)?

## 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) and inner [join](https://www.mindstick.com/articles/1487/join-sleep-and-interrupt-methods-in-c-sharp-threading) are both SQL join clauses that are used to combine data from two or more tables. However, they have different purposes and should be used in different situations.

**Cross apply** is used to create a Cartesian product of two tables. This means that it will return all possible combinations of rows from the two tables, even if there is no matching row in the other table.

**Inner join** is used to join two tables based on a common value. This means that it will only return rows from the two tables where there is a matching row in the other table.

In general, you should use cross apply when you want to return all possible combinations of rows from two tables. For example, you might use cross apply to get a list of all possible orders that could be made from a list of products and a list of customers.

You should use inner join when you want to return only the rows that match between two tables. For example, you might use inner join to get a list of all orders that were made by a specific customer.

Here is a table that summarizes the differences between cross apply and inner join:

| Feature | Cross apply | Inner join |
| --- | --- | --- |
| Creates a Cartesian product | Yes | No |
| Returns all possible combinations of rows | Yes | No |
| Returns only matching rows | No | Yes |
| When to use | When you want to return all possible combinations of rows | When you want to return only matching rows |

Here is an example of how to use cross apply:

SQL

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

This code will return all possible combinations of rows from the `Customers` table and the `Orders` table. This means that it will return all rows from the `Customers` table, even if there are no matching rows in the `Orders` table.

Here is an example of how to use inner join:

SQL

```plaintext
SELECT *
FROM Customers
INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID;
```

This code will return only the rows from the `Customers` table that have a matching row in the `Orders` table. This means that it will only return rows from the `Customers` table where there is a corresponding order in the `Orders` table.


---

Original Source: https://www.mindstick.com/forum/159033/when-should-i-use-cross-apply-over-inner-join

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
