选择多个表时使用多个LIKE

时间:2015-09-25 04:11:06

标签: mysql

我在选择多个表时尝试使用多个LIKE。我的SQL查询如下。

SELECT users.*, threads.* 
FROM users, threads 
WHERE users.Username LIKE ? 
OR threads.Name LIKE ?

然而,如果我只有一个LIKE,就像这样......

SELECT users.*, threads.* 
FROM users, threads 
WHERE users.Username LIKE ?

我应该如何多次使用LIKE?

2 个答案:

答案 0 :(得分:0)

尝试此查询:

SELECT users.*, threads.* FROM users, threads WHERE (users.Username LIKE ? OR threads.Name LIKE ?)

答案 1 :(得分:0)

检查下面的查询,我试过下面的例子。它对我来说很好,

SELECT users.*, threads.* 
FROM users, threads 
WHERE users.Username LIKE '?' 
OR threads.Name LIKE '?'

例如

select p.name,bi.mrp 
from billitem bi,product p 
where p.name like 'a%' 
or bi.productname like 'ta%'