SQL:复合查询

问题描述 投票:1回答:2

是否可以形成一个查询,其中table1.first_name +“”+ table1.last_name匹配table2.customer_name?

IE:customers.first_name =“John”customers.last_name =“Doe”

orders.customer_name =“John Doe”

在我看来,这将是一个常见的查询,但只是无法直观地提出语法。

此外,我被认为这不是一个“最佳实践”解决方案(使用id字段会更好),但如果我无法控制架构,我只想知道我的方法之类的东西是否可能。

mysql sql sql-server
2个回答
2
投票

您正在寻找concat

where concat(customers.first_name,' ',customers.last_name) = orders.customer_name 

0
投票

您可以连接值并比较结果,如下所示:

(customers.first_name || ' ' || customers.last_name) = orders.customer_name

支架只是为了便于阅读

© www.soinside.com 2019 - 2024. All rights reserved.