[英]Use '%' with column names in MYSQL select statement?
I have a query that looks at partial matches within two mysql tables to make a join: 我有一个查询,查找两个mysql表中的部分匹配以进行联接:
SELECT table1.column, table2.column FROM table1, table2 WHERE table1.val LIKE table2.val
This works fine as a join, but... some of the values in table2 are actually substrings of the values in table one—specifically they're urls. 可以很好地用作联接,但是... table2中的某些值实际上是表一中值的子字符串-特别是它们是url。 So, table1.val might equal http://google.com while table2.val = google.com.
因此,table1.val可能等于http://google.com,而table2.val = google.com。
How do I use the '%' operator around the table2 val to make this comparison. 如何使用table2 val周围的'%'运算符进行此比较。
Thanks in advance! 提前致谢!
Like this: 像这样:
... WHERE table1.val LIKE CONCAT('%', table2.val, '%')
Note that this will not perform as well as table1.val = table2.val
, as it must now search all rows in table2
. 请注意,此方法的性能不如
table1.val = table2.val
,因为它现在必须搜索table2
所有行。
Q: How do I use the '%' operator around the table2 val to make this comparison.
问:如何使用table2 val周围的'%'运算符进行此比较。
A: You don't :) 答:你不:)
You can specify a column by name (eg "mycolumn"), by fully qualified name (eg "mytable.myname") or by ordinal (eg "1"). 您可以按名称(例如“ mycolumn”),完全限定名称(例如“ mytable.myname”)或序数(例如“ 1”)指定列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.