如何在列名中使用LIKE

问题描述:

通常LIKE语句用于检查数据之类的模式.

Normally LIKE statement is used to check the pattern like data.

示例:

select * from table1 where name like 'ar%'

我的问题是在LIKE语句中使用表的一列.

My problem is to use one column of table with LIKE statement.

示例:

select * from table1, table2 where table1.x is like table2.y%

查询以上结果错误.如何在like查询中使用一列数据?

Query above results error . how to use one column data in like query?

您已经关闭.

LIKE运算符可用于字符串(CHAR,NVARCHAR等).因此您需要在字符串中包含'%'符号...

The LIKE operator works with strings (CHAR, NVARCHAR, etc). so you need to concattenate the '%' symbol to the string...


MS SQL Server:

MS SQL Server:

SELECT * FROM table1,table2 WHERE table1.x LIKE table2.y + '%'


但是,使用LIKE通常比其他操作慢.它是有用,强大,灵活的,但是具有性能方面的考虑.我会把这些留给另一个话题:)


Use of LIKE, however, is often slower than other operations. It's useful, powerful, flexible, but has performance considerations. I'll leave those for another topic though :)


我不使用MySQL,但这可能有效...

I don't use MySQL, but this may work...

SELECT * FROM table1,table2 WHERE table1.x LIKE CONCAT(table2.y, '%')