Illustration Image

Query for the most recent file version in a folder

I'm trying to get all the file_id items for the most recent version for the specified folder_id for the example_table defined below in Cassandra. Is this possible, or is my data designed incorrectly for my use case?

example_table

folder_id (Partition Key) file_id (Clustering Key) version (timestamp Clustering Key) ORDER DESC
1 1 2
1 1 1
1 2 2
1 2 1
1 3 2
1 3 1

I'm thinking the query would be something like this, but I'm not able to get it working.

SELECT folder_id,file_id,MAX(version) FROM example_table WHERE folder_id=1;

desired result

folder_id (Partition Key) file_id (Clustering Key) version (timestampClustering Key) ORDER DESC
1 1 2
1 2 2
1 3 2
Become part of our
growing community!
Welcome to Planet Cassandra, a community for Apache Cassandra®! We're a passionate and dedicated group of users, developers, and enthusiasts who are working together to make Cassandra the best it can be. Whether you're just getting started with Cassandra or you're an experienced user, there's a place for you in our community.
A dinosaur
Planet Cassandra is a service for the Apache Cassandra® user community to share with each other. From tutorials and guides, to discussions and updates, we're here to help you get the most out of Cassandra. Connect with us and become part of our growing community today.
© 2009-2023 The Apache Software Foundation under the terms of the Apache License 2.0. Apache, the Apache feather logo, Apache Cassandra, Cassandra, and the Cassandra logo, are either registered trademarks or trademarks of The Apache Software Foundation. Sponsored by Anant Corporation and Datastax, and Developed by Anant Corporation.

Get Involved with Planet Cassandra!

We believe that the power of the Planet Cassandra community lies in the contributions of its members. Do you have content, articles, videos, or use cases you want to share with the world?