If I join table A to table B like this...
select A.* from A
left outer join B on A.Id = B.aId and @param = 'someValue'
and @param does not equal 'someValue', does SQL Server even attempt to match records from table B or is it smart enough to know the condition will never be true?
SELF JOIN: As the name signifies, in SELF JOIN a table is joined to itself. That is, each row of the table is joined with itself and all other rows depending on some conditions. In other words we can say that it is a join between two copies of the same table.
SQL JOIN. A JOIN clause is used to combine rows from two or more tables, based on a related column between them. Notice that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column.
Yes, you can JOIN views with tables. You can use views just like tables in SELECTs. Special considerations apply in other operations. A view can be thought of as either a virtual table or a stored query.
So while in a particular context you may find that the when @param has a different value then the outer join table may never be probed, you should not rely on it for correctness. Note that probe means that actual values are searched for in the table. The metadata information will always be checked. For example you cannot cheat and ask for a join to a table that doesn't exists.
In particular, do not attempt to create a single query where there should be two different ones (one that joins, one that doesn't).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With