Simple Query

15 views
Skip to first unread message

gamm...@gmail.com

unread,
Feb 20, 2016, 12:52:58 PM2/20/16
to YapDatabase
Dear Robbie,

assume we have an employee collection and each employee has a salary. How would you perform
the following query using yap database: "Which employee has the highest salary?"

Thank you!


Robbie Hanson

unread,
Feb 20, 2016, 1:14:47 PM2/20/16
to yapda...@googlegroups.com
Start by creating a secondary index:


You’ll want to include employee.salary in your index. (Of course, you’re not limited to just one item in a secondary index, so you can include other things as well.)

Once that’s up, you’re ready to execute queries against the secondary index.

> "Which employee has the highest salary?"

Technically, you might have multiple employees that all have the same salary, which is also the highest salary in the company. So I’d actually break it up into 2 queries:

1. What’s the MAX(salary) ?
2. Enumerate the employees WHERE salary = max_salary

So query #1 is an aggregate query:

And query #2 is a standard query (now that you know max_salary):

Hope that helps.

-Robbie Hanson


--
You received this message because you are subscribed to the Google Groups "YapDatabase" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yapdatabase...@googlegroups.com.
To post to this group, send email to yapda...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages