How do we know this? Take a look at the first two rows in the student_course table. The sole purpose of this table is to connect the student and course tables together.įor example, “Shreya Bain” (the student with id = 1) is connected to “English literature” (the course with id = 2) and “Python programming” (the course with id = 3). It’s important to notice that the student_course table is a junction table. Meanwhile, take a look at the example data from these three tables: We’ll use the teacher table later in the course in more advanced queries. teacher_id – The ID of the teacher for that course.course – Contains information about the courses:.student_course – Contains information about which students go to which courses:. last_name – The last name of the student.first_name – The first name of the student.student – Contains information about students:.Our example data is stored in four tables.Right now, we’ll focus on the first three tables: For further information about reading a schema, see the article Crow’s Foot Notation on the Vertabelo blog. For example, there’s a reference between the student and student_course tables – each student can be linked to multiple rows in the student_course table. In the above entity-relationship diagram (ERD), you can see tables, their columns, the columns’ data types, and the references between tables. We’ll get deeper into the query and tables in the next section. We’ve simply repeated the JOIN clause and joined three tables. ON student.id = student_course.student_id The truth is that you can easily extend this idea to three tables or even more. That’s not surprising – this concept can be hard to understand, and the idea that JOINs can get even more complicated may be really scary at first. If you’ve just learnt JOINs in SQL, you might think that it’s limited to two tables. It covers a wide range of topics from simple 2-table JOINs, through joining multiple tables and using OUTER JOINs, to joining a table with itself. It contains over 90 hands-on exercises that let you refresh your SQL JOINs knowledge. The best way to practice SQL JOINs is 's interactive SQL JOINs course. You can join 3, 4, or even more! The possibilities are limitless. Using JOIN in SQL doesn’t mean you can only join two tables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |