adding sorting constraints to database

simplifying queries
making other queries easier to read
Merge pull request #135 from IMOD-ASU/optimize-queries

Optimize Queries