SELECT LIMFT JOIN与LIMIT

时间:2014-04-11 21:30:58

标签: php mysql sql

我在限制Jokes表格中的行数方面存在问题。

这是我的查询工作,获取所有行:

SELECT Jokes.ID, Categories.CategoryName, Jokes.CategoryID, Jokes.JokeText 
FROM Jokes 
LEFT JOIN Categories 
ON Jokes.CategoryID = Categories.ID 
ORDER BY Jokes.ID DESC

它会是什么样的?

SELECT Jokes.ID, Categories.CategoryName, Jokes.CategoryID, Jokes.JokeText 
FROM (
SELECT * FROM Jokes ORDER BY ID DESC Limit 0,40) 
AS a 
LEFT JOIN Categories 
AS b 
ON a.CategoryID = b.ID

1 个答案:

答案 0 :(得分:3)

为什么不使用

SELECT Jokes.ID, Categories.CategoryName, Jokes.CategoryID, Jokes.JokeText 
FROM Jokes 
LEFT JOIN Categories 
ON Jokes.CategoryID = Categories.ID 
ORDER BY Jokes.ID DESC
Limit 0,40