Can anybody please tell me how to write query to update top 1 record in table ?
Thanks
Can anybody please tell me how to write query to update top 1 record in table ?
Thanks
There is no "top 1 record" in a relational table. Records are not in any order unless you specify one in the query.
YOU have to decide what the top record is in a table, by ordering against a column you decide on.
That said, you could do this in SQL Server:
UPDATE [YourTable]
SET [YourColumn] = SomeValue
WHERE [PrimaryKey] IN
(
SELECT TOP 1 [PrimaryKey]
FROM [YourTable]
ORDER BY [PrimaryKey] -- You need to decide what column you want to sort on
)
in SQLServer you can use the TOP keyword in your update expression:
http://msdn.microsoft.com/en-us/library/ms177523.aspx
When a TOP (n) clause is used with UPDATE, the update operation is performed on a random selection of 'n' number of rows.
Hi all
this is tina thanks for ur help,I m using SQL 2008
The query below is working:
update top(1) ShipBillInfo set shipfirstname='kkk' where CustomerId='134';
but it is showing error if i try to order by some Id: for example:
update top(1) ShipBillInfo set shipfirstname='kkk' where CustomerId='134' order by OredrGUID desc;
Plz help!
Thanks
Tina