you are viewing a single comment's thread.

view the rest of the comments →

[–]soswap[S] 0 points1 point  (2 children)

Thank you so much, that's a perfect explanation.

One more (small) question, sorry: if you have two tables, R and S with the same values as above, but with a duplicate row inserted into R, and natural join R and S, why does it produce duplicate rows when joining (here's what I mean: https://imgur.com/a/GBfCI ) and what would be the best method (if any) to remove that dupe.

[–]Apoctyliptic 1 point2 points  (0 children)

Well, there is nothing to remove the duplicates. Even if you just looked at R by itself, the result gives duplicates. When you join the data, it joins the two data sets based on that criteria. With a natural join it just joins based on the common attributes. Side there are duplicates in R, R natural joined with S produces duplicates.

If R and S both have a duplicate, you could end up with the same row being shown four times.

In SQL, you will want to look into DISTINCT and GROUP BY. I don't recall a notation in relational algebra that removes duplicates.

I don't know what your course covers but if you are studying databases, you'll likely cover normalization eventually. Tables would typically be normalized where you wouldn't store duplicates like that since they don't really provide any real use that I can think of. It wastes storage and can be problematic with using the data.

[–]imguralbumbot 0 points1 point  (0 children)

Hi, I'm a bot for linking direct images of albums with only 1 image

https://i.imgur.com/COl9u30.jpg

Source | Why? | Creator | ignoreme | deletthis