I want to Join multiple tables using IF ELSE statement within Sql Query when column value match with the specified text.
Suppose I have checked coloumnName='Value' Then I want to JOIN an additional Table; otherwise, I do not want to join it. Is this possible? How can I do that?
You cannot conditionally join a table You need to join all tables unconditionally using an outer join, use the condition in the join criteria, and pick the values that you want from the returned data set, like this:
The example above shows “requests” that have an
item_idthat references a person, an animal, or a thing. Thetypecolumn decides which table is referenced.The result will have three columns for
name, at most one of which will be non-null.