Adobe Interview Question | SQL Interview Question no 20 | Daily SQL Practice | Advanced SQL
ฝัง
- เผยแพร่เมื่อ 8 ก.พ. 2025
- In SQL, CROSS APPLY is used to join two tables (or a table and a table-valued function) where one of the tables can return multiple rows for each row of the other table. This is particularly useful when you want to perform row-by-row operations or when you need to use functions that return table results, as CROSS APPLY allows you to access columns from both sides of the join.
Here's a breakdown to help understand it better:
Key Concepts of CROSS APPLY
Row-by-Row Join: CROSS APPLY is like a looped join. For each row in the left table, it applies the logic defined in the right side (often a table-valued function or subquery).
Filtering Rows: Unlike CROSS JOIN, CROSS APPLY allows you to filter rows in the right table (or function) based on values from the left table.
Used for Complex Queries: It’s particularly useful in cases where the logic involves functions that return table results or nested queries that need input from each row.
SELECT columns
FROM LeftTable
CROSS APPLY RightTableOrFunction
The STRING_SPLIT function in SQL Server is used to split a string into multiple rows based on a specified delimiter. This is helpful when you have a list of values in a single string column and want to break them into individual rows.
SELECT value
FROM STRING_SPLIT (string, delimiter);
string: The string you want to split.
delimiter: The character or substring used as the separator to split the string.
The STRING_SPLIT function returns a single column named value with each part of the split string in a new row.
Example 1: Basic String Splitting
Suppose you have a string Apple,Orange,Banana that you want to split by commas.
.
.
.
.
.
.
#SQL #SQLInterviewQuestions #LearnSQL #DataAnalysis #SQLQuery #InterviewTips #Database #programming #SQLInterviewQuestions
#SQLQuestionsAndAnswers
#SQLInterviewPrep
#SQLQueries
#SQLForBeginners
#SQLTips
#SQLTutorial
#SQLDeveloper
#DatabaseInterview
#SQLSkills
#SQLJobInterview
#TechInterviewPrep
#DataEngineer
#SQLProgramming
#LearnSQL
#SQLQueryExamples
#SQLAdvanced
#SQLInterviewGuide
#TechInterviews
#SQLAndDatabase
.
.
.
.
-----------------------------Table Script-------------------------------------
create table tags(id int, tag varchar(20))
insert into tags values (1, '#200#100#100#300')
insert into tags values (2, '#200#200#300#400') - วิทยาศาสตร์และเทคโนโลยี