create account

Weekly Tech Lesson: CROSS JOINs Versus CROSS APPLY by sqlinsix

View this thread on: hive.blogpeakd.comecency.com
· @sqlinsix ·
$0.76
Weekly Tech Lesson: CROSS JOINs Versus CROSS APPLY
https://www.youtube.com/watch?v=H3Stc86AoNs&list=PLHHm85xMQAYNScEs-nu9gzi2uoQ9JCCYA&index=9

<p>When we look at data, we will sometimes want to look at all data points relative to all other data points.  We discussed this when we talked about CROSS APPLY, but we must remember that CROSS APPLY pertains to SQL Server only.  In many SQL languages we can use CROSS JOINs.  From this functionality, we can look at every record relative to every other record - for instance, if we have data for 12 months, we look at each month relative to all months (including itself).  In the video, <a href="https://www.youtube.com/watch?v=H3Stc86AoNs&list=PLHHm85xMQAYNScEs-nu9gzi2uoQ9JCCYA&index=9">SQL Basics: How To Use A CROSS JOIN and Why</a>, we look at anexample of using this functionality. </p>

<p>Note the tables that we're using and what values are identical based on the column names and what values differ based on the column names. We'll be using these tables throughout these videos. As a note on aliasing tables - the first table always gets a "t1" while the second table always gets a "t2" and so on and so forth (the 5th table would get a "t5"). Finally, consider that some SQL languages may not support the JOINs that we discuss.  As a quick reminder, not all SQL languages may support the exact syntax shown.  We've discussed CROSS APPLY and while this may be similar to CROSS JOIN, there are differences (I highlight these toward the end of the video), but more SQL languages support CROSS JOIN - just note that the differences.  While CROSS JOIN does have the "multiple" result set that we can see in CROSS APPLY, it does not take in parameters like CROSS APPLY (as an example), so it is still restricted in use.  It does however result in a multiple result set as we see.</p>

<p>In the example, we CROSS JOIN our two tables, which only have 2 overlapping values between tables.  A large percent of the time, we'll use CROSS JOIN on a table itself, but it's useful to use CROSS JOIN on two tables because we'll sometimes do this.  Also, we don't filter; for instance, if I had filtered where values equal, our result set would be different.  Keep this in mind when you CROSS JOIN two tables where you need to filter strictly because of the values that you're comparing - for instance, if we want to compare a month's data to every other month, then we need to filter accordingly (for instance, on the first table we may only select one value and compare to every other value). </p>
👍  , , , , , , ,
👎  
properties (23)
authorsqlinsix
permlinkweekly-tech-lesson-cross-joins-versus-cross-apply
categoryhive-199420
json_metadata"{"tags":["hive-199420","sql","sqlserver","development","data"],"image":["https://img.youtube.com/vi/H3Stc86AoNs/0.jpg"],"links":["https://www.youtube.com/watch?v=H3Stc86AoNs&list=PLHHm85xMQAYNScEs-nu9gzi2uoQ9JCCYA&index=9"],"app":"hiveblog/0.1","format":"markdown","description":"How does CROSS JOIN and CROSS APPLY differ?"}"
created2021-08-15 09:24:18
last_update2021-08-15 09:24:18
depth0
children1
last_payout2021-08-22 09:24:18
cashout_time1969-12-31 23:59:59
total_payout_value0.381 HBD
curator_payout_value0.378 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,489
author_reputation4,698,858,647,110
root_title"Weekly Tech Lesson: CROSS JOINs Versus CROSS APPLY"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id105,552,619
net_rshares993,274,155,314
author_curate_reward""
vote details (9)
@gangstalking ·
I upvoted you, thank you for posting! 👍
👎  ,
properties (23)
authorgangstalking
permlinkre-sqlinsix-weekly-tech-lesson-cross-joins-versus-cross-apply-20210815t092426643z
categoryhive-199420
json_metadata{"app":"hive-bot/0.6.3"}
created2021-08-15 09:24:27
last_update2021-08-15 09:24:27
depth1
children0
last_payout2021-08-22 09:24:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length39
author_reputation-67,597,107,868,724
root_title"Weekly Tech Lesson: CROSS JOINs Versus CROSS APPLY"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id105,552,621
net_rshares-26,501,247,438
author_curate_reward""
vote details (2)