MySql :: use Limit和OrderBy

时间:2013-01-26 08:45:35

标签: mysql sql

当我尝试运行此查询时,我在最后一行收到语法错误,这是在我添加限制 orderby 之后发生的:

DROP PROCEDURE IF EXISTS `SP_GetFilesInfo`;

CREATE DEFINER = `root`@`localhost` PROCEDURE `SP_GetFilesInfo`(pFileID varchar(20),pFileName varchar(100),pExrtention int,pParentID varchar(20),pSize int,pReferenceID int,pIndex int,pNumOfRec int)
BEGIN
SELECT  FileID,
                FileName,
                FilePath,
                Size,
                Exrtention,             
                ParentID,
                IsFolder,
                ModificationDate,               
                filesrefrences.ReferenceID,
                filesrefrences.RefrenceCount,
                filesrefrences.RefrenceKey
from filesinfo LEFT OUTER JOIN filesrefrences ON   (filesrefrences.ReferenceID = filesinfo.ReferenceID)

WHERE       (pFileID=-99 OR pFileID is NULL OR filesinfo.FileID=pFileID)
                AND (pFileName='' OR pFileName is NULL OR filesinfo.FileName LIKE CONCAT('%', pFileName,'%'))
                AND (pExrtention=-99 OR pExrtention is NULL OR filesinfo.Exrtention =pExrtention)
                AND (pParentID=-99 OR pParentID is NULL  OR filesinfo.ParentID=pParentID)               
                AND (filesinfo.ReferenceID= pReferenceID OR pReferenceID=-99 OR pReferenceID is NULL)
                AND (filesinfo.Size=pSize OR pSize=-99 OR pSize is NULL)  ORDER BY IsFolder DESC LIMIT 0;           
END;

1 个答案:

答案 0 :(得分:2)

如果未提供LIMIT要显示的记录数),则duration的值应大于0

ORDER BY IsFolder DESC 
LIMIT 1;

如果您提供了持续时间,则结果中第一条记录的索引为零,例如

ORDER BY IsFolder DESC 
LIMIT 0, 1;

其中0索引1持续时间