我的SQL Server中的LIMIT子句问题 [英] LIMIT Clause Problem in My SQL Server
问题描述
我有以下情况
+ -------- + -------- + ------- ---------- + ------------------------- +
| Msgid |用户ID |消息| MsgDate |
+ -------- + -------- + ----------------- + --- ---------------------- +
| 3 | 75 | TextMSG | 2014-04-01 12:05:29.957 |
| 4 | 75 | TextMSG | 2014-04-01 12:06:14.967 |
| 5 | 75 | TextMSG | 2014-04-01 12:06:48.160 |
| 6 | 80 | TextMSG | 2014-04-01 12:07:02.227 |
| 7 | 80 | TextMSG | 2014-04-01 12:07:07.763 |
+ -------- + --------- + ------- + --- ------------------------------- +
并写用于检索用户ID 75的最近2个消息的查询。
SELECT Msg FROM TempNoti WHERE UserID = 75 LIMIT 2 ORDER BY MsgDate DESC ;
但它出现以下错误
'LIMIT'附近的语法不正确。
我使用本网站的教程mysqltutorial 。
如果是MySQL,请尝试:
< pre lang =SQL> SELECT 消息
FROM TempNoti
WHERE UserID = 75
ORDER BY MsgDate DESC
LIMIT 2 ;
请使用正确的标签。
LIMIT必须是SELECT语句中的最后一项:
SELECT 消息 FROM TempNoti WHERE UserID = 75 ORDER BY MsgDate DESC LIMIT 2
SELECT TOP 2 消息 FROM Te mpNoti WHERE UserID = 75 ORDER BY MsgDate DESC ;
I have the following scenario
+--------+--------+-----------------+-------------------------+
| Msgid |UserID | Msg | MsgDate |
+--------+--------+-----------------+-------------------------+
| 3 | 75 | TextMSG | 2014-04-01 12:05:29.957 |
| 4 | 75 | TextMSG | 2014-04-01 12:06:14.967 |
| 5 | 75 | TextMSG | 2014-04-01 12:06:48.160 |
| 6 | 80 | TextMSG | 2014-04-01 12:07:02.227 |
| 7 | 80 | TextMSG | 2014-04-01 12:07:07.763 |
+--------+---------+-------+----------------------------------+
and write the query to retrieve the 2 recent msg of User id 75.
SELECT Msg FROM TempNoti WHERE UserID = 75 LIMIT 2 ORDER BY MsgDate DESC;
But it gives the following error
Incorrect syntax near 'LIMIT'.
I using the tutorial from this site mysqltutorial.
If it is MySQL, try:
SELECT Msg FROM TempNoti WHERE UserID = 75 ORDER BY MsgDate DESC LIMIT 2;
Please, use proper tag.
LIMIT must be the last thing in the SELECT Statement:
SELECT Msg FROM TempNoti WHERE UserID = 75 ORDER BY MsgDate DESC LIMIT 2
SELECT TOP 2 Msg FROM TempNoti WHERE UserID = 75 ORDER BY MsgDate DESC;
这篇关于我的SQL Server中的LIMIT子句问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!