Click here to Skip to main content
15,914,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Exper,

I've a .sdf db file. i want to delete first row from a table.

SQL
DELETE TOP (1) FROM   myTable
is not working.

Please let me know wht is the alternative for this.
Posted
Updated 20-Aug-12 23:58pm
v2

Well, it probably is - but since you don't specify an order, you can't really tell, as the rows that are deleted will depend on the internal order of records, rather than any order you have applied (or think you have applied).

If you want to delete specific records from the top, then you need to select the appropriate records and delete those. The safest general purpose way to do it is:
SQL
DELETE FROM myTable WHERE id IN (SELECT TOP 1 id FROM myTable ORDER BY myOrderColumn)
 
Share this answer
 
Comments
vidiking 21-Aug-12 8:43am    
Thank you. But this is giving error in .sdf file.

DELETE FROM myTable WHERE id IN (SELECT TOP 1 id FROM myTable ORDER BY myOrderColumn)
where
1. myTable : is my table name fron .sdf file
2. myOrderColumn : is the column header of the table
OriginalGriff 21-Aug-12 9:59am    
And the error is?
If your tags are correct and you're using MySQL, you can use LIMIT clause to retrieve the top records and to delete them.

For example:
SQL
DELETE FROM TheTable
WHERE ...
ORDER BY ...
LIMIT 1;


For more information: DELETE Syntax[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900