Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:01:22+00:00 2026-05-29T19:01:22+00:00

I have been looking at CROSS / OUTER APPLY with a colleague and we’re

  • 0

I have been looking at CROSS / OUTER APPLY with a colleague and we’re struggling to find real life examples of where to use them.

I’ve spent quite a lot of time looking at When should I use CROSS APPLY over INNER JOIN? and googling but the main (only) example seems pretty bizarre (using the rowcount from a table to determine how many rows to select from another table).

I thought this scenario may benefit from OUTER APPLY:

Contacts Table (contains 1 record for each contact)
Communication Entries Table (can contain a phone, fax, email for each contact)

But using subqueries, common table expressions, OUTER JOIN with RANK() and OUTER APPLY all seem to perform equally. I’m guessing this means the scenario isn’t applicable to APPLY.

Please share some real life examples and help explain the feature!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:01:23+00:00Added an answer on May 29, 2026 at 7:01 pm

    Some uses for APPLY are…

    1) Top N per group queries (can be more efficient for some cardinalities)

    SELECT pr.name,
           pa.name
    FROM   sys.procedures pr
           OUTER APPLY (SELECT TOP 2 *
                        FROM   sys.parameters pa
                        WHERE  pa.object_id = pr.object_id
                        ORDER  BY pr.name) pa
    ORDER  BY pr.name,
              pa.name 
    

    2) Calling a Table Valued Function for each row in the outer query

    SELECT *
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
    

    3) Reusing a column alias

    SELECT number,
           doubled_number,
           doubled_number_plus_one
    FROM master..spt_values
    CROSS APPLY (SELECT 2 * CAST(number AS BIGINT)) CA1(doubled_number)  
    CROSS APPLY (SELECT doubled_number + 1) CA2(doubled_number_plus_one)  
    

    4) Unpivoting more than one group of columns

    Assumes 1NF violating table structure….

    CREATE TABLE T
      (
         Id   INT PRIMARY KEY,
    
         Foo1 INT, Foo2 INT, Foo3 INT,
         Bar1 INT, Bar2 INT, Bar3 INT
      ); 
    

    Example using 2008+ VALUES syntax.

    SELECT Id,
           Foo,
           Bar
    FROM   T
           CROSS APPLY (VALUES(Foo1, Bar1),
                              (Foo2, Bar2),
                              (Foo3, Bar3)) V(Foo, Bar); 
    

    In 2005 UNION ALL can be used instead.

    SELECT Id,
           Foo,
           Bar
    FROM   T
           CROSS APPLY (SELECT Foo1, Bar1 
                        UNION ALL
                        SELECT Foo2, Bar2 
                        UNION ALL
                        SELECT Foo3, Bar3) V(Foo, Bar);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking online to find documentation for the function in QTP and
I have been looking everywhere but could not find a tutorial for this. I
Possible Duplicate: Developing cross platform mobile application I have been tasked with looking into
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking around for a visualization framework that would aid graph visualization
I have been looking into AWS spot instances for some jobs however instead of
I have been looking into backbone.js and I can't seem to figure out how
I have been looking at the Thinktecture.IdentityModel.40 library as a way of handling the
I have been looking for an answer to this on Stack Overflow, but I
I have been looking through the source code for the Flash-based Google TV example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.