在mysql查询中使用少于运算符卡住

时间:2013-11-08 18:31:45

标签: mysql sql

我只需要pbox.id<'".$pbid."' and cbox.id<'".$cbid."'的数据,但它不起作用。我尝试了很多东西仍然不起作用,它获取所有数据。它看起来不像运营商。我是如何解决这个问题的?

SELECT DISTINCT pbox.id as pbid,
cbox.id as cbid,
box.upload_type,
box.id,
box.box_type,
box.page_name,
box.title,
box.connect,
box.type,
box.uid,
box.description,
box.image,
box.url,
box.status,
box.date,
box.time
FROM boxes as box
LEFT JOIN page_boxes as pbox on pbox.bid=box.id
JOIN page_subcribers as pages on pages.page_id=pbox.page_id 
LEFT JOIN category_boxes as cbox on cbox.bid=box.id 
LEFT JOIN subcribers as catsb on cbox.category_id=catsb.cid 
WHERE pages.uid='".$session_id."' or catsb.uid='".$session_id."' and box.status='".$approval."' and cbox.id<'".$cbid."' and pbox.id<'".$pbid."'
ORDER BY pbox.id desc,cbox.id DESC LIMIT 10

1 个答案:

答案 0 :(得分:2)

尝试使用WHERE子句上的括号强制运算符优先级: -

SELECT DISTINCT pbox.id as pbid,
cbox.id as cbid,
box.upload_type,
box.id,
box.box_type,
box.page_name,
box.title,
box.connect,
box.type,
box.uid,
box.description,
box.image,
box.url,
box.status,
box.date,
box.time
FROM boxes as box
LEFT JOIN page_boxes as pbox on pbox.bid=box.id
JOIN page_subcribers as pages on pages.page_id=pbox.page_id 
LEFT JOIN category_boxes as cbox on cbox.bid=box.id 
LEFT JOIN subcribers as catsb on cbox.category_id=catsb.cid 
WHERE (pages.uid='".$session_id."' 
or catsb.uid='".$session_id."')
and box.status='".$approval."' 
and cbox.id<'".$cbid."' 
and pbox.id<'".$pbid."'
ORDER BY pbox.id desc,cbox.id DESC 
LIMIT 10