Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

sql - What's a zip join? Have you ever heard of that, or a pairwise join?

This section of Slick's documentation page is quite odd.

What is this zip join? It says that it means:

a pairwise join of two queries

but what that means @.@ I don't know

I've tried Googling for both "zip join" and "pairwise join"... but no results to do with databases.

I do get this from Wikipedia when I search on "pairwise" though...


Could somebody give me some examples illustrating the differences between a zip join and a normal outer or inner join? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Zip joins are only meaningful when talking about ordered sets. Instead of joining based on the value of a column, you are joining based on the row number.

Table1

[λ]  [color] 
400  violet 
415  indigo 
475  blue   
510  green  
570  yellow 
590  orange 
650  red    

Table2

[flame]  [element]
green    boron
yellow   sodium
white    magnesium
red      calcium
blue     indium

Table1 INNER JOIN Table2 ON [color] = [flame] : only matching rows

[λ]  [color]  [flame]  [element]
475  blue     blue     indium 
510  green    green    boron
570  yellow   yellow   sodium
650  red      red      calcium

Table1 OUTER JOIN Table2 ON [color] = [flame] : all rows, matched where possible

[λ]  [color]  [flame]  [element]
400  violet   NULL     NULL
415  indigo   NULL     NULL
475  blue     blue     indium
510  green    green    boron
570  yellow   yellow   sodium
590  orange   NULL     NULL
650  red      red      calcium
NULL NULL     white    magnesium

Table1 "zip joined" to Table2 : all rows, regardless of match

[λ]  [color]  [flame]  [element]
400  violet   green    boron
415  indigo   yellow   sodium
475  blue     white    magnesium
510  green    red      calcium
570  yellow   blue     indium
590  orange   NULL     NULL
650  red      NULL     NULL

Zip joins are combining the data like a zipper, pairing the first row from one table with the first row from the other, second paired with second, etc. It's not actually looking at that data. They can be generated very quickly, but they won't mean anything unless there is some meaningful order already present in your data or if you just want to generate random pairings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...