테이블을 조인할 때 얼마나 많은 작업이 필요한지 감을 잡을 수 있게 지난 12개월 동안 전자제품 액세서리를 구매한 고객 이름을 출력하는 의사코드를 살펴보자.
for cust in get_customers(): for order in get_customer_orders(cust.customer_id): if today() - 365 <= order.order_date: for order_item in get_order_items (order.order_id): if 'electronic accessories' = get_product_category(order_item.product_id): customer_set = add_item (customer_set,cust.name); for customer_name in customer_set: print customer_name;
이 예제 코드에서 get_customers, get_customer_orders, get_order_items 함수는 로우 리스트를 반환한다. get_customers()는 모든 고객을 반환한다.
get_customer_orders 함수가 호출될 때마다 customer_id를 매개변수로 넘겨주어 해당 고객 ID가 있는 주문만 반환한다. get_order_items 함수가 호출될 때는 order_id를 넘겨줘 order_id가 있는 주문만 반환한다.
점(.)을 찍은 것은 반환될 로우에 있는 필드를 뜻한다. 예를 들어 order.order_date는 특정 주문에 있는 order_date 값을 반환한다. 마찬가지로 cust.name은 현재 cust라는 변수로 참조되고 있는 고객의 이름을 반환한다.