Oracle/SQL - Join one table multiple times to the same table -
i'm trying wrap brain around query , hoping can help. have 2 tables: customer_table , product_table this
name sku_num1 sku_num2 sku_num3 sku_num4 ---------------------------------------------------- bob b c d frank e tom g shelly g e justin e g sku_num widget_name ------------------- widget_a b widget_b c widget_c d widget_d
so want return list of customers have @ least 1 product sku appears in product table. above information receive records for
bob
frank
justin
any ideas how this?
there no need join 1 table twice:
select * customers sku_num1 in (select sku_num product_table) or sku_num2 in (select sku_num product_table) ....
the reason why need multiple conditions full table scan on product_table
wrong database design. products customer bought should not go multiple columns in customer table. instead should have third table n:m relation between customer , products.
Comments
Post a Comment