In SQL server I can say:
Select top 50 percent
How can I say bottom 50 percent?
EDIT - for the sake of an interesting question, if we assume he has a table with a primary key but wants the bottom 50% ordered in ascending primary key order. What would be the most efficient way of achieving that?
Your question as stated is technically meaningless because without an order by clause the order in which your data is returned is undefined (in practice most databases will return in primary key order, or if you don't have a primary key then in insertion order, but that is not guaranteed)
Assuming however you have an order by clause but just haven't included it, just would use DESC instead of ASC.
Another option could be:
You can then dynamically change the division of your data as you like.
Check this out.
Does not work correct when the table contains a uneven amount of records. the one in the middle will be in both result sets.
this on the other hand works fine
upvote for mingos :)
downvote for user151323 :(
why not just change the sort order and keep TOP. Wouldn't that accomplish the same thing?
I dunno whether this would work:
And I'm pretty sure something like this would be OK too:
Just check the syntax, as I'm only beginning to learn SQL and can't form correct queries without modifying the a million times first ;)