我在 SQL Server 中有这个表:
ID | videoid | title
=========================
1 | id1 | title1
2 | id2 | title2
3 | id3 | title3
我想创建在标题行中搜索的选择方法:
SELECT * FROM [movie].[dbo].[movies]
WHERE title like '%' + '%s' + '%'
我在 MySQL 中寻找类似 Limit 的东西,从 SELECT
结果中我将能够得到 0-20,21-40,41-60
结果。
对这个查询有帮助吗?
我尝试使用 LIMIT 0, 10
并收到此错误:
Could not find stored procedure 'LIMIT'.
最佳答案
您需要将 TOP N
与 SQL SERVER 一起使用。
SELECT TOP 10 * FROM [movie].[dbo].[movies]
WHERE title like '%' + '%s' + '%'
ORDER BY SomeColumn -- Specify your column for ordering
Limits the rows returned in a query result set to a specified number of rows or percentage of rows in SQL Server
另请参阅 Best Practices in docs .
In a SELECT statement, always use an ORDER BY clause with the TOP clause. This is the only way to predictably indicate which rows are affected by TOP.
如果您正在寻找寻呼记录,那么您将需要 ROW_NUMBER
关于c# - 带限制的 SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22455057/