subscriptions.descriotion 에서 subscriptions를 빼도 무방. 하지만 이걸 주의해야할 때가 있음.
inner join
subscrptions.descriptions
subscriptions.description
Primary keys have a few requirements:
- None of the values can be NULL.
- Each value must be unique (i.e., you can’t have two customers with the same customer_id in the customers table).
- A table can not have more than one primary key column.
Note that customer_id (the primary key for customers) and subscription_id (the primary key for subscriptions) both appear in this
When the primary key for one table appears in a different table, it is called a foreign key.
So customer_id is a primary key when it appears in customers, but a foreign key when it appears in orders.
중요한 이유
when we join orders and customers, we join on customer_id, which is a foreign key in orders and the primary key in customers.
Sometimes we just want to stack one dataset on top of the other.
- Tables must have the same number of columns.
- The columns must have the same data types in the same order as the first table.
- JOIN will combine rows from different tables if the join condition is true.
- LEFT JOIN will return every row in the left table, and if the join condition is not met, NULL values are used to fill in the columns from the right table.
- Primary key is a column that serves a unique identifier for the rows in the table.
- Foreign key is a column that contains the primary key to another table.
- CROSS JOIN lets us combine all rows of one table with all rows of another table.
- UNION stacks one dataset on top of another.
- WITH allows us to define one or more temporary tables that can be used in the final query
'SQL > 공부' 카테고리의 다른 글
select 문 총정리 (0) | 2023.07.09 |
---|---|
개념적 데이터 모델링, ERD (0) | 2023.02.07 |
Codecademy - Aggregate Functions (0) | 2023.02.05 |
Codecademy - Queries (0) | 2023.02.05 |
sql select문, join (생활코딩) (0) | 2023.02.04 |