目前我在下面打印了简单的mysql SELECT
查询。
"SELECT * FROM pictures WHERE views > $views_min ORDER BY $rating_or_something_other DESC LIMIT $index , $pics_per_page";
我想找到所有未暂停的照片,但问题是暂停状态位于另一张桌子上:
表pictures
有pictures.gallery_id
列,我想检查galleries.id
表格中的id
,我的最后一点是gallery.hold
状态。根据这些数据,我希望仅得到所有未暂停的pictures.*
(按图库)。
我正在尝试这样的事情,但似乎需要使用JOINS
?
"SELECT p.*, g.id, g.hold FROM pictures AS p, galleries AS g
WHERE p.views > $views_min AND p.gallery_id = g.id AND g.hold <> 1 ORDER BY p.rating(?) DESC LIMIT $index, $pics_per_page;
答案 0 :(得分:0)
为什么要阻止使用连接?就这么简单:
SELECT p.*, g.id, g.hol FROM pictures AS p
INNER JOIN galleries as g ON g.id = p.gallery_id
WHERE p.views > $views AND g.hold <> 1
ORDER BY p.rating(?) DESC
LIMIT $index, $pics_per_page;