# Query

**URL:** <https://www.ruby-forum.com/t/query/155730>\
**Category:** Rails\
**Created:** [December 16, 2008, 3:52am UTC](https://www.ruby-forum.com/t/query/155730 "2008-12-16T03:52:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![newb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/2acd7d/32.png) [@newb](https://www.ruby-forum.com/u/newb)\
**Post date:** [December 16, 2008, 3:52am UTC](https://www.ruby-forum.com/t/query/155730/1 "2008-12-16T03:52:01Z")

</div>

Hi…  
Actually i need to get

User’s name  
Contact’s name and it’s department id and it’s Authority id and  
authority name.  
so i done following query.  
but its so long.  
I don’t know about join queries.  
so pls help me how can i implemend join query instead of below query…

user = UserInfo.find\_by\_id(user\_id)

=\>Using this query I get user.first\_name

contact = UserInfo.find\_by\_id(contact\_id)

=\>Using this query I get contact.first\_name and contact.department\_id

authority = PrivilegeInfo.find(:first, :conditions =\> [ "user\_id =? and  
department\_id =? ", contact\_id,contact.department\_id])

=\>Using this query I get authority.authority\_id

authority\_name = UserInfo.find\_by\_id(authority.authority\_id)

=\>Using this query I get authority\_name.first\_name

Thanks in advance
