# ActiveRecord question - how to find owners of at least one c

**URL:** <https://www.ruby-forum.com/t/activerecord-question-how-to-find-owners-of-at-least-one-c/113683>\
**Category:** Rails\
**Created:** [September 3, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/activerecord-question-how-to-find-owners-of-at-least-one-c/113683 "2007-09-03T22:23:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rykkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e5b9ba/32.png) [@rykkers](https://www.ruby-forum.com/u/rykkers)\
**Post date:** [September 3, 2007, 10:23pm UTC](https://www.ruby-forum.com/t/activerecord-question-how-to-find-owners-of-at-least-one-c/113683/1 "2007-09-03T22:23:10Z")

</div>

Hopefully the subject is clear enough.

Let’s say I’ve got two tables:

create\_table :bands do | b |  
b.column :name, :string  
end

create\_table :concerts do | c |  
c.column :where, :string  
c.column :when, :date  
c.column :band\_id, :integer  
end

and the models:

class Band \<\<ActiveRecord::Base  
has\_many :concerts  
end

class Concert \<\< ActiveRecord::Base  
belongs\_to :band  
end

What I’d like to do is find all of the Bands which have at least one  
concert on or after a given date.

In this case there are lots of concerts which makes this a bit  
performance critical.

I’ve not been able to figure out how to do this through ActiveRecord  
so as to generate an efficient SQL query, or how to do it manually  
using find\_by\_sql either. It’s a bit complicated also since SQL date  
comparison function seems to be somewhat database dependent.

Any ideas from the community?
