Let's say you have the following two tables:
X Table
X_ID Y_ID_F X_Value
1 1 Q
2 1 G
3 1 T
4 2 W
5 2 K
...
Y Table
Y_ID Y_Value
1 A
2 B
...
You want to query only those properties whose Y parent's value is A and update them so you write a query as follows (I realize there is a better query but bear with me):
UPDATE X set X_Value = 'O'
WHERE X_ID IN
(
select distinct X.X_ID FROM X
INNER JOIN Y ON X.Y_ID_F = Y.Y_ID
WHERE Y.Y_Value = 'A'
)
I previously thought that this would do what it seemingly says : Update the rows of the X table where the joined Y table's Y_Value = 'A'. However it seems that the X.X_ID causes all rows in the X table to be updated, not just the ones you'd think the WHERE clause restricted it to. Somehow that X.X_ID causes the query to completely ignore the attempt of the where clause at restricting the set of updated rows. Any ideas on why?
EDIT: I think it may have something to do with the way the tables in the database I am querying are associated and not as simple as the example I tried to equivocate it to.