Reputation: 116
I want to limit to only 10 results, something like below.
I have searched online but cannot find a solution.
SELECT [Id], [Name], [Age], [Date], [Time]
FROM [People]
LIMIT 10;
Upvotes: 0
Views: 119
Reputation: 424
You can use
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time] FROM [People]
now it depends on you in which order you want i mean
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time] FROM [People] order by Asc or desc
Upvotes: 0
Reputation: 98740
LIMIT
is a MySQL Syntax.
T-SQL has TOP
DML Statement for that.
Limits the rows returned in a query result set to a specified number of rows or percentage of rows in SQL Server 2012. When TOP is used in conjunction with the ORDER BY clause, the result set is limited to the first N number of ordered rows; otherwise, it returns the first N number of rows in an undefined order.
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time]
FROM [People]
ORDER BY [Id]
Upvotes: 2
Reputation: 937
You can use,
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time]
FROM [People]
or
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time]
FROM [People]
ORDER BY [Id] DESC -- Descending Order View
Upvotes: 0
Reputation: 28741
No you haven't searched . Anyways here it is
SELECT TOP 10 [Id], [Name], [Age], [Date], [Time] FROM [People]
Note :
Without ORDER BY
clause , this will give random 10 records
Upvotes: 4