Re: Cartesian product in query
it's because you are joining the tables (so c.customerid appears multiple times) and have no limiting function.
what you're doing is joining two tables
basically in table 1 you have say customerid and customer name
in table 2 you have customerid and order id
this is a relational database and enables multiple customers to place multiple orders.
so you have 10 customers, (10 customer id's in the customers table).
they've placed 50 orders.
when you select with your query you're joining the
table 1 looks like
table two looks like
your query is returning the joined tables so the customer id for dave is getting returned as many times as he's ordered stuff.
change the query to select * from customers c inner join orders o on c.customerid=o.customerid and you'll see what I mean about the combined table
you can use select unique if you want to join in this way. (to do what I think you're trying to do)
I guess you're trying to return the customer Id's of people who have ordered.
i.e you can't just say select from customers because steve would be returned even though he's ordered nothing
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."