how to use a like with a join in sql?

后端 未结 5 1276
无人及你
无人及你 2020-11-30 23:27

I have 2 tables, say table A and table B and I want to perform a join, but the matching condition has to be where a column from A \'is like\' a column from B meaning that an

5条回答
  •  悲&欢浪女
    2020-11-30 23:53

    Using conditional criteria in a join is definitely different than the Where clause. The cardinality between the tables can create differences between Joins and Where clauses.

    For example, using a Like condition in an Outer Join will keep all records in the first table listed in the join. Using the same condition in the Where clause will implicitly change the join to an Inner join. The record has to generally be present in both tables to accomplish the conditional comparison in the Where clause.

    I generally use the style given in one of the prior answers.

    tbl_A as ta
        LEFT OUTER JOIN tbl_B AS tb
                ON ta.[Desc] LIKE '%' + tb.[Desc] + '%'
    

    This way I can control the join type.

提交回复
热议问题