English subtitles

← Related Tables - Intro to Relational Databases

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. So a database,
    will usually have several tables in it.
  2. Here's how we might start for
    our image voting app.
  3. The first table represents pictures
    that people have uploaded of animals.
  4. The second represents people's votes.
  5. Fluffy, Monster, and
  6. George are all animals,
    whose pictures someone has uploaded.
  7. Because, we might have two
    animals with the same name.
  8. We give each one a numeric id here.
  9. The pictures tables says
    that Fluffy has id 1.
  10. Monster has id 2.
  11. George has id 3.
  12. And so on.
  13. The votes table says, which images
    have been displayed together for
  14. voting, and
    which one the user picked as the cutest.
  15. Here, the app displayed monster,
    ID 2, and George, ID 3,
  16. and the user voted for George.
  17. 2 and 3 were matched up,
    and 3 was the winner.
  18. Note that in the votes table,
  19. the columns are called left,
    right, and winner.
  20. But they match up, to the column
    called id in the pictures table.
  21. You can read every row as a sentence.
  22. In the pictures table, the sentences
    say Fluffy has id number 1, and
  23. the filename fluffsocute.jpg,
    Monster has id number 2,
  24. and filename monstie-basket.png and
    so forth.
  25. In the votes table,
    the sentences are picture 2 and
  26. picture 3, were displayed and
    the user voted for picture 3.
  27. Picture 1 and
    picture 3 were displayed, and
  28. the user voted for picture 1 and so on.
  29. So this 3 and this 3, refer to the same
    thing, a cute critter with id number 3.
  30. But they're in different tables, and
    the columns have different names,
  31. because they play different
    roles in different sentences.
  32. Over here we're saying,
    which picture has which id?
  33. And over here we're saying, which ones
    have been displayed together, and
  34. who got the vote?
  35. So this is the kind of sentence that
    this table actually represents.
  36. If you wanted to come up with sentences
    like Monster was shown to Fluffy, and
  37. Fluffy got the vote instead
    of 2 was shown with 1,
  38. and 1 got the vote for this row here.
  39. We would have to connect rows from
    this table, with rows from that table.
  40. That's something we can do
    with a database query as well.
  41. Queries that do this are called joins,
  42. we'll be seeing a lot of
    them later on in the course.
  43. For now, just remember that
    a value with the same meaning,
  44. can occur in different tables and
    have different column names, and
  45. that we can derive new tables by
    linking up existing tables using joins.