简体   繁体   English

SQL:检查列是否包含另一个SELECT语句的值

[英]SQL: Check if column contains value from another SELECT statement

I wanted to join the below two tables: 我想加入以下两个表:

Table 1: 表格1:

---------
| Brand |
---------
| Honda |
| Dodge |
| Toyota|
---------

Table 2 Survey Table: 表2调查表:

------------------------------------------
|Ser|          Comments                  |
------------------------------------------
| 1 | Honda is a reliable brand          |
| 2 | The dodge Challenger is pure muscle|
| 3 | The new Toyota Corolla is a treat  |

Now I want to join both these tables and get Table 3 : 现在我想加入这两个表并得到表3:

--------------------------------------------------
|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|

How do I get Table 3? 我如何获得表3?

I am not being able to Compare both the Comments and the brand list to see if the comments contain the brand name and if yes take the Brand Name. 我无法比较评论和品牌列表,看看评论是否包含品牌名称,如果是,则采用品牌名称。 Any help would be great. 任何帮助都会很棒。

You can try JOIN on like 您可以尝试JOINlike

SELECT * 
FROM Table1 t1 INNER JOIN Table2 t2 
ON t2.Comments like '%'+t1.Brand  +'%'

Sqlfiddle Sqlfiddle

Use LIKE: Where UPPER(comments) LIKE '%' || 使用LIKE:其中UPPER(注释)LIKE'%'|| brand || 品牌|| '%' '%'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Sql 查询以检查第 1 列的 substring 是否包含另一列的值 - Sql query to check if substring of column 1 contains is value of another column SQL从一个表列中选择一个最小值,然后将结果插入一个SQL语句的另一个表列中 - Sql Select a minimum value from a table column and insert the results in another table column in one SQL statement SQL / SQlite:根据另一列的值在选择语句中添加一列 - SQL/SQlite: Adding a column in a select statement based on a value of another column SQL根据另一个Select语句从表中选择列 - SQL Select Column From Table Based on Another Select Statement 如何检查/选择字符串是否包含表列值中的值? - How to check/select if a string contains value from a table column values? 从另一个表减去列的总和 - SQL select 语句 - Sum of column minus column from another table - SQL select statement SQL Server从一列中选择最大值,然后检查该值是否存在于另一张表中 - SQL Server select the max value from one column and check if the value exists in another table SQL选择基于另一列的SQL选择列不等于参数,但在具有相同值的另一列中包含参数 - Sql select column based on another column not equaling the parameter but contains the parameter in another column with same value 检查一列的值是否包含另一列的值 - Check if the value of one column contains the value of another 检查第 2 列的值是否包含在 sql 的第 1 列中 - check if value of column 2 contains in column 1 in sql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM