课程: Practice It: SQL Joins

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Understanding self joins

Understanding self joins

- [Instructor] A self-join is also known as a recursive relationship when a column in a table is related to the same column in the same table. The self-join is useful for comparing values in a column to other values in the same column. Let's say we need a list of all products in the same product sub-category. We can use a self-join in this case on the dim product table. In the following SQL statement, we perform an inner join on the dim product table to the same dim product table and in the "on" criteria, we choose the product keys that don't match, but are in the same product sub-category. The resulting data set gives us all of the products that are in the same product sub-class as a product in the first column. It also gives us the product subcategory key in the last column. In some RDBMSs, we can add a foreign key referencing that primary key of the same table in an alter statement. However, in SQLite, we aren't able to…

内容