You need to use TOP(1) in SQL Server. The syntax is as follows −
SELECT TOP(1) *FROM yourTableName WHERE yourCondition;
To understand the above syntax, let us create a table. The query to create a table is as follows −
create table TopDemoInSQLServer ( Id int, Name varchar(10) );
The snapshot of creation of table is as follows −
Insert some records in the table using insert command. The query is as follows −
insert into TopDemoInSQLServer values(10,'John'); insert into TopDemoInSQLServer values(14,'Carol'); insert into TopDemoInSQLServer values(1,'Sam'); insert into TopDemoInSQLServer values(11,'Bob'); insert into TopDemoInSQLServer values(18,'David'); insert into TopDemoInSQLServer values(20,'Sam');
The snapshot of insert record in the table is as follows −
Display all records from the table using select statement. The query is as follows −
select *from TopDemoInSQLServer;
The snapshot of displaying all records from the table is as follows −
Output
Here is the query to implement TOP(1) instead of LIMIT 1 −
select TOP(1) *from TopDemoInSQLServer where Name = 'Carol';
Here is the snapshot of query −
Here is the snapshot of sample output −