i have 2 tables in same database, 1 called "products" , other called "customers", need customer.order_id, customer.name, customer.order_total, products.type thing need matching result if there 1 product customer, if customer have more 1 product on other table ignore , skip next one.
i have following sql inner joins need,but don't know how filter results based on product count (i don't want display customer if got more 1 product.
for example
customers table order_id name order_total 13445 john 650 28837 steve 300 20039 craig 200 39487 matt 475 products table order_id product_sku product_price product_type 13445 12345 650 toys 28837 34434 175 pool 28837 54453 125 food 20039 43546 200 toys 39487 34256 475 food what need 2 tables is:
order_id name order_total product_type 13445 john 650 toys 20039 craig 200 toys 39487 matt 475 food i've tried that, gets me result including customers more 1 product
select customer.order_id, customer.name, customer.order_total, products.type customer inner join products on customer.order_id=products.order_id customer.order_total != 0 order customer.order_id desc please help, thank you
both should work:
select c.*,p.product_type customers c, products p c.order_id = p.order_id , c.order_id in (select order_id products group by(order_id) having count(order_id) = 1); select c.*, p.product_type products p , customers c c.order_id = p.order_id group by(p.order_id) having count(p.order_id) = 1;
Comments
Post a Comment