Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL CE: Limiting rows returned in the query

In SQL Compact Edition 3.5 , note that it is the Compact Edition I am talking about- Is there a way to limit the amount of rows to only 2? Something like using LIMIT or TOP. I really don't want to use anything with a SqlCEDataReader, or SqlCEResultSet. I want to do all the limiting in the query. Is this possible now? I have looked around and it doesn't seem so.

EDIT-

In response to Dave Swersky's request for data and using Min()/Max() on some columns as a means to get the top 2 lines, here is some sample (sterilized) data:

Line     Site          Function     Status
1010     Las Vegas     new          4
1020     DC            send         1
1030     Portland      copy         1
1040     SF            copy         1
1050     Portland      copy         1
1060     DC            send         1

*There are more columns than this but these are the significant ones.

Sorry for the lack of intuitive data (but the actual data is even less intuitive!), but for security i need to change the data.

So- i need to determine: what site the record was at in the preceding line to determine where it needs to be picked up.

The site on any given line (except the first line with function = 'new') corresponds to where the item is going next. So simply grabbing that site off the same line wont tell me where it came from. The status will always be 1 or 4. The 4 corresponds to a where it has been delivered already and so i dont want to include those records in the result. But it might be useful in getting the pickup site.

For this table of data i want the query to return the site corresponding to the line just above the first line with status 1. So- for this it would be Las Vegas.

like image 459
Dostee Avatar asked Nov 22 '25 08:11

Dostee


2 Answers

Sql CE 3.5 supports the TOP expression: http://technet.microsoft.com/en-us/library/bb686896.aspx

like image 59
user227997 Avatar answered Nov 23 '25 23:11

user227997


This will depend on your data... if you have guaranteed-sequential IDs or dates you could use MAX with NOT IN subqueries to return a limited number of rows. Post some of your schema and I'll try to cook up an example.

like image 25
Dave Swersky Avatar answered Nov 23 '25 22:11

Dave Swersky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!