views:

50

answers:

1

Hello guys I've been trying to compare two similar tables that have some different columns

Table 1 has columns ID_A, X, Y, Z and Table 2 has columns ID_B, X, Y, Z

If both values from columns X or Y or Z are = 1 the result of the query would output columns

ID_A, ID_B, X, Y, Z

I thought it would be an intersect statement in there, but I'm having problems because the name of the columns and the values from ID_A and ID_B are completely different.

What would this SQL statement look like? I'd appreciate any ideas, been banging my head on the wall for this one.

+1  A: 

To output rows that are in both tables, an inner join would work:

select       *
from         table1 a
inner join   table2 b
on           a.x = b.x and a.y = b.y and a.z = b.z

To list only rows with x=1, y=1, or z=1 in both tables, add a where clause like;

where        a.x = 1 or a.y = 1 or a.z = 1
Andomar
But how would you add the parameter of if x,y,or z = 1
Chris Allen
@Chris Allen: You could add a where clause for that? answer edited
Andomar