# Find\_by\_sql help on site search

**URL:** <https://www.ruby-forum.com/t/find-by-sql-help-on-site-search/122792>\
**Category:** Rails\
**Created:** [December 12, 2007, 7:04am UTC](https://www.ruby-forum.com/t/find-by-sql-help-on-site-search/122792 "2007-12-12T07:04:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [December 12, 2007, 7:04am UTC](https://www.ruby-forum.com/t/find-by-sql-help-on-site-search/122792/1 "2007-12-12T07:04:04Z")

</div>

Hello,

Thanks for taking a look and offering up your help!

I’m trying to set up a way my site visitor can search my site via  
band.name and videos.name simultaneously, for up to 10 results. The  
names should be searched for any and all keywords entered. I think I’m  
close, but my query doesn’t return any results for me, but I’m not  
getting any errors.

Important Associations: band has\_many videos while videos belongs\_to  
bands.

@search\_b = search\_terms.compact.join(" OR b.name LIKE “)  
@search\_v = search\_terms.compact.join(” OR v.name LIKE ")  
@results = Video.find\_by\_sql([“SELECT b.name, v.name FROM bands b,  
videos v WHERE b.id = v.band\_id AND v.name LIKE ? OR b.name LIKE ?”,  
@search\_v , @search\_b])

RoR is my first language, so if my code seems inefficient, please don’t  
be too harsh. 😉 I’m just trying to find a way to make it work.

Thanks!
