I had a question about the above SQL code. Looking at the code, the query 'where b.customer_id is not null' is searching for non-null values in the customer_id column. However, there are no null values in the b.customer_id column, and null values in b.name and b.age are excluded. I was curious about the reason for this.
select a.order_id,
a.customer_id,
a.restaurant_name,
a.price,
b.name,
b.age,
b.gender
from food_orders a left join customers b on a.customer_id=b.customer_id
where b.customer_id is not null
The condition "b.customer_id is not null" is used to select rows in the "food_orders" table where the "customer_id" column is not NULL. This does not mean rows in the "customers" table where the "customer_id" column is not NULL, but rather it signifies rows in the joined result where the "customer_id" column of the "food_orders" table is not NULL.
Therefore, the condition "b.customer_id is not null" selects only rows from the join result of the "food_orders" table and the "customers" table where the "customer_id" is not NULL. Hence, rows with NULL values in the "b.name" and "b.age" columns are excluded from the resulting set.
'Issue Note' 카테고리의 다른 글
Difference between 'num for num in range' and 'for num in range' (Python) (0) | 2024.04.02 |
---|---|
Difference between list and [] (Python) (0) | 2024.04.02 |
DATE - [SQL} (0) | 2024.04.01 |
Table name from Subquery [SQL] (0) | 2024.03.21 |
Red highlighted error [SQL] (0) | 2024.03.21 |