MySQL 如何修改SQL语句,去掉语句中的or,因为有or导致索引失效
select bid from book a ,querybook b where ( a.bname in (b.bname) or b.bname = "" ) and
(a.bauthor in (b.bauthor) or b.bauthor = "" ) and
(a.barea in (b.barea) or b.barea = "" )
SQL作用是当查询条件为空时默认查询全部数据,不为空是则按照条件进行查询
不知道你想表达什么意思,为什么要判断为空
但是你可以这样
select bid from book a ,querybook b
where a.bname in (b.bname) and a.bauthor in (b.bauthor) and a.barea in (b.barea)
UNION
select bid from book a ,querybook b
where b.barea = "" and b.bname = "" and b.bauthor = ""
代码仅供参考,你可以举一反三