Database Management Exam  >  Database Management Videos  >  SQL Server Administration: Basic Tutorials  >  Cross apply and outer apply in sql server

Cross apply and outer apply in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

148 videos

FAQs on Cross apply and outer apply in sql server Video Lecture - SQL Server Administration: Basic Tutorials - Database Management

1. What is the difference between CROSS APPLY and OUTER APPLY in SQL Server?
Ans. CROSS APPLY and OUTER APPLY are two types of table-valued operators in SQL Server. The main difference between them is how they handle the unmatched rows between the two tables being joined. CROSS APPLY only returns rows where there is a match between the two tables. It acts like an inner join, filtering out rows that do not have a corresponding match in the other table. OUTER APPLY, on the other hand, returns all the rows from the left table (the table being applied to) and includes the matching rows from the right table. If there is no match, it returns NULL values for the columns of the right table.
2. When should I use CROSS APPLY in SQL Server?
Ans. CROSS APPLY is useful when you want to filter the rows from the left table based on some condition in the right table. It allows you to use a correlated subquery to perform the filtering, making it more flexible than a regular join. For example, if you have a table of orders and a table of products, and you want to retrieve all the orders along with the products that were ordered, you can use CROSS APPLY to join the two tables and filter out the products that were not ordered.
3. When should I use OUTER APPLY in SQL Server?
Ans. OUTER APPLY is useful when you want to include all the rows from the left table regardless of whether there is a match in the right table. It is particularly handy when you want to retrieve additional information from the right table, even if there is no direct match. For example, if you have a table of employees and a table of departments, and you want to retrieve all the employees along with their respective department names, you can use OUTER APPLY to include the department name for each employee, even if some employees do not belong to any department.
4. Can CROSS APPLY and OUTER APPLY be used with multiple tables?
Ans. Yes, both CROSS APPLY and OUTER APPLY can be used with multiple tables. You can chain them together to apply multiple table-valued operators in a single query. For example, if you have three tables A, B, and C, and you want to retrieve all the rows from A along with the matching rows from B and C, you can use CROSS APPLY or OUTER APPLY with multiple joins.
5. Are CROSS APPLY and OUTER APPLY specific to SQL Server only?
Ans. No, CROSS APPLY and OUTER APPLY are specific to SQL Server and are not available in all database management systems. They are part of the T-SQL language, which is the dialect of SQL used by SQL Server. Other database management systems may have similar functionality using different syntax or features. If you are working with a different database system, you should consult its documentation to find the equivalent functionality.
148 videos
Explore Courses for Database Management exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

Previous Year Questions with Solutions

,

video lectures

,

Exam

,

Semester Notes

,

shortcuts and tricks

,

Extra Questions

,

mock tests for examination

,

Objective type Questions

,

Important questions

,

Viva Questions

,

Cross apply and outer apply in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

pdf

,

past year papers

,

ppt

,

Cross apply and outer apply in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

MCQs

,

Sample Paper

,

study material

,

Free

,

Cross apply and outer apply in sql server Video Lecture | SQL Server Administration: Basic Tutorials - Database Management

,

Summary

,

practice quizzes

;