0

I want to delete some records that are on the top by the date and time.

the error is near 2, (the value of no_of_recordss)

DELETE TOP " + no_of_recordss + " FROM [upload_news] WHERE [country]='" + countryy.Text + "' ORDER BY [upload_time] ASC"
Sidra Kanwal
  • 115
  • 9
  • 2
    MySQL doesn't use TOP: http://stackoverflow.com/questions/2249905/is-there-an-alternative-to-top-in-mysql – John Conde Mar 25 '14 at 15:32
  • You mean: DELETE LIMIT " + no_of_recordss + " FROM [upload_news] WHERE [country]='" + countryy.Text + "' ORDER BY [upload_time] ASC @ John Conde – Sidra Kanwal Mar 25 '14 at 15:36
  • 1
    Your syntax suggests SQL Server. The question is tagged MySQL. What database are you using? – Gordon Linoff Mar 25 '14 at 15:58

1 Answers1

1

Try like this

;WITH CTE AS
(
SELECT TOP " + no_of_recordss + " *
FROM [upload_news] 
WHERE [country]='" + countryy.Text + "' 
ORDER BY [upload_time] ASC
)
DELETE FROM CTE
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115