帮改个Sql语句问题,谢谢
SELECT id,name FROM tb_category WHERE (id = 11) OR (id = (SELECT fid FROM tb_category AS b_category_1 WHERE (id = 322))) AND (fid = 11) OR (id = 322) 我想要的是
第一页显示的是id 322的那个,不要316的。
------解决方案--------------------贴出你的数据,还有你的结果
------解决方案--------------------SELECT id,name FROM tb_category WHERE
(id = 11) OR
(
id = (
SELECT fid FROM tb_category AS b_category_1 WHERE (id = 322)
)
AND (fid = 11))
OR (id = 322)
------解决方案--------------------SELECT id,name
FROM tb_category
WHERE id = 11
OR id = (SELECT fid FROM tb_category AS b_category_1 WHERE id = 322)
AND fid = 11
OR id = 322
只给你把语句简化了一下,你先自己看清楚这个逻辑对不对,AND和OR不加括号混用是本意吗
------解决方案--------------------你这个是查询tb_category表的id=322并且fid=11或者id=11或者id=322,and的优先级比or高,想控制需要加()