2013-06-05 69 views
-1

有人可以幫我解決這個問題嗎?Mysql JOIN和WHERE問題

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

WHERE走後FROM(畢竟JOIN S)

FROM 
    gallerythumbs AS a 
    JOIN galleryimages AS b USING (id) 
WHERE 
    gallery = 1 

USING(id)在這種情況下可能不正確。您可能想使用類似ON (a.id = b.galleryid)的東西。

+0

非常感謝! –

+0

@GlenRogers不要忘記接受有用的答案 –

+0

對不起,我花了這麼長時間,現在接受答案!................ –