Created
January 20, 2011 23:28
-
-
Save connrs/788928 to your computer and use it in GitHub Desktop.
Gets all the notes left by anyone for a service that is registered as yours via Service.user_id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT Note.created ucreated, Note.id FROM customers Customer JOIN services Service JOIN notes Note ON (Service.customer_id=Customer.id AND Note.service_id=Service.id) WHERE (Note.user_id=1 OR Service.user_id=1) | |
# I really want to expand this to include notes left by anyone for a customer that has a service belonging to you (yet the note is customer specific not service specific via a HasMany relationship) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The original statement that does everything including not-associated-to-service notes:
The hacky count query: