Reputation: 785
I have a query that selects a bunch of rows from various tables and orders them alphabetically based on a single field (Fruit), but I want to only start selecting after a certain value is reached. Is there anyway of doing this in MS Access SQL?
Eg:
If the value is Cherry and the table, ordered alphabetically, looks like:
**Fruit:**
Apple
Banana
Cherry
Damson
Orange
--
Then I just want to select Cherry, Damson and Orange. (Sorry I couldn't think of a fruit beginning with E)
Thanks for your help in advance!
Upvotes: 6
Views: 8208
Reputation: 36601
If you create an id
column in your fruit table
then it would be easy to get the list of rows after a certain row.
you table will look like.
id fruitname
----------- --------------------
1 Apple
2 Banana
3 Cherry
4 Damson
5 Orange
And query will look like.
SELECT * FROM fruit f
WHERE id>=(SELECT id FROM fruit WHERE fruitname='Cherry');
this will result in
id fruitname
----------- --------------------
3 Cherry
4 Damson
5 Orange
Upvotes: 2
Reputation: 69759
Most operators can also be applied to text fields, so in your example you could use:
SELECT *
FROM Fruit
WHERE FruitName >= 'Cherry'
Upvotes: 8