Mysql JOIN和WHERE问题

时间:2013-06-05 19:47:54

标签: mysql

有人可以帮我解决这个问题吗?

SELECT  a.filename AS thumbpath, b.filename AS imagepath, name 
FROM gallerythumbs AS a WHERE gallery = 1
JOIN galleryimages AS b 
USING(id) ORDER BY id DESC 
LIMIT   $start, $per_page

我有3个图库,数据被添加到msqyl表中。每个图库都会在图库字段中放置1,2或3个。

我在哪里放这行

WHERE gallery = 1

感谢您寻找

1 个答案:

答案 0 :(得分:1)

WHERE追踪FROM(在所有JOIN之后)

FROM
    gallerythumbs AS a
    JOIN galleryimages AS b USING (id)
WHERE
    gallery = 1
在这种情况下,

USING(id)可能不正确。您可能希望使用类似ON (a.id = b.galleryid)的内容。