Other than @ThomasRushton's answer of joining on a subset, there are a few other cases that I can think of. The first is a cross join. If you need a Cartesian product, that's where you go. In this case, if you have 3 rows in table A and 5 rows in table B, you'll get 15 rows. Don't do this with large sets...
The second case is what I would call a "one-sided" join. These are functionally equivalent to cross joins, but look different:
select
*
from
dbo.A a
inner join dbo.B b on b.Number = 25;
This does the same thing as a cross join with a where clause. This is NOT a good idea, because somebody glancing at your code might overlook the fact that you aren't really doing an inner join as we normally think of it--you're really doing a cross join and filtering the results.
After that, we can draw the logical implication from @ThomasRushton's subset: a superset. Join A to B on A.Something = (B.Col1 + B.Col2). We could also do a range, which is common in warehousing: where A.SomeDate between B.BeginDate and B.EndDate. Or you could do a clause where A.Value > B.SomeOtherValue--though this borders on Cross Join + Where as well.
These are possible, but most of the examples here aren't [SARGable][1]. Not being SARGable will have a negative effect on query performance, especially for larger tables.
[1]: http://en.wikipedia.org/wiki/Sargable
↧