I’m using an MS Access .mdb database in my C# application. The database contains email messages (one row – one message).
I need to get a specified amount of messages which are older than a specified datetime. Let’s say, 30 messages before 2012-02-01 12:00:00. I’ve tried different queries but all of them give me errors. Have tried the TOP, LIMIT and other statements also:
"SELECT * FROM ( SELECT * FROM Mails WHERE (timeReceived < ?) ) LIMIT 0,30";
"SELECT * FROM Mails WHERE (timeReceived = ?) ORDER BY timeReceived DESC LIMIT ?";
etc.
Any hints appriciated.
You say you’ve tried TOP clause, but it should work
You must take this into account.
Edit to clarify:
http://office.microsoft.com/en-us/access-help/results.aspx?qu=top&ex=1&origin=HA010256402
So, no, rows with the same timestamp are not skipped. But if the 30th and 31th records(according to the order clause) have the same timestamp, both will be returned and you get 31 records.
If you want to force 30 records to be returned, you need to include the primary key into the
Order Byto differentiate between tied values: