Rows dropping when I try to join data from two tables
Posted
by blcArmadillo
on Stack Overflow
See other posts from Stack Overflow
or by blcArmadillo
Published on 2010-06-08T19:16:31Z
Indexed on
2010/06/08
19:22 UTC
Read the original article
Hit count: 442
I have a fairly simple query I'm try to write.
If I run the following query:
SELECT parts.id, parts.type_id FROM parts WHERE parts.type_id=1 OR parts.type_id=2 OR parts.type_id=4 ORDER BY parts.type_id;
I get all the rows I expect to be returned. Now when I try to grab the parent_unit from another table with the following query six rows suddenly drop out of the result:
SELECT parts.id, parts.type_id, sp.parent_unit FROM parts, serialized_parts sp WHERE (parts.type_id=1 OR parts.type_id=2 OR parts.type_id=4) AND sp.parts_id = parts.id ORDER BY parts.type_id
In the past I've never really dealt with ORs in my queries so maybe I'm just doing it wrong. That said I'm guessing it's just a simple mistake. Let me know if you need sample data and I'll post some. Thanks.
© Stack Overflow or respective owner