SQL:检查列是否包含来自另一个SELECT语句的值
我想加入以下两个表: 表1:SQL:检查列是否包含来自另一个SELECT语句的值,sql,sql-server,join,ssms,Sql,Sql Server,Join,Ssms,我想加入以下两个表: 表1: --------- | Brand | --------- | Honda | | Dodge | | Toyota| --------- ------------------------------------------ |Ser| Comments | ------------------------------------------ | 1 | Honda is a reliable brand
---------
| Brand |
---------
| Honda |
| Dodge |
| Toyota|
---------
------------------------------------------
|Ser| Comments |
------------------------------------------
| 1 | Honda is a reliable brand |
| 2 | The dodge Challenger is pure muscle|
| 3 | The new Toyota Corolla is a treat |
--------------------------------------------------
|Ser| Comments | Brand |
--------------------------------------------------
| 1 | Honda is a reliable brand | Honda |
| 2 | The dodge Challenger is pure muscle| Dodge |
| 3 | The new Toyota Corolla is a treat | Toyota|
表2调查表:
---------
| Brand |
---------
| Honda |
| Dodge |
| Toyota|
---------
------------------------------------------
|Ser| Comments |
------------------------------------------
| 1 | Honda is a reliable brand |
| 2 | The dodge Challenger is pure muscle|
| 3 | The new Toyota Corolla is a treat |
--------------------------------------------------
|Ser| Comments | Brand |
--------------------------------------------------
| 1 | Honda is a reliable brand | Honda |
| 2 | The dodge Challenger is pure muscle| Dodge |
| 3 | The new Toyota Corolla is a treat | Toyota|
现在我想加入这两个表并得到表3:
---------
| Brand |
---------
| Honda |
| Dodge |
| Toyota|
---------
------------------------------------------
|Ser| Comments |
------------------------------------------
| 1 | Honda is a reliable brand |
| 2 | The dodge Challenger is pure muscle|
| 3 | The new Toyota Corolla is a treat |
--------------------------------------------------
|Ser| Comments | Brand |
--------------------------------------------------
| 1 | Honda is a reliable brand | Honda |
| 2 | The dodge Challenger is pure muscle| Dodge |
| 3 | The new Toyota Corolla is a treat | Toyota|
我怎么才能拿到3号桌
我无法比较评论和品牌列表,以查看评论是否包含品牌名称,如果是,则使用品牌名称。任何帮助都会很好 像这样使用:
如果上面的(注释)像“%”| | brand | |“%”你可以在
像上尝试加入
SELECT *
FROM Table1 t1 INNER JOIN Table2 t2
ON t2.Comments like '%'+t1.Brand +'%'