Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:45:51+00:00 2026-06-01T16:45:51+00:00

How can I make this query into a scope in rails 3.2? The point

  • 0

How can I make this query into a scope in rails 3.2?
The point is to access two different table entries and pick info that is common to both of them.

SELECT u1.FirstName, u2.FirstName
FROM User AS u1, User AS u2
WHERE u2.LastName=u1.LastName

Do you know other way to achieve this with better performance?

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:45:52+00:00Added an answer on June 1, 2026 at 4:45 pm

    Assuming I understand your question, you can do this:

    User.joins('join users as u2 on users.last_name = u2.last_name and users.id != u2.id')
    

    This will give you all the users that have the same last name as any other user.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me make this query loop into an efficient Linq query? I
Possible Duplicate: How can I make this query to accept dynamic table names? I
How can i make multiple, composite query in oracle? for example this several queries
I tried in different ways to accomplish this but I can make it work
I did my reading on this and still can't make sense why my query
How i can make this condition en VB.NET If e.KeyCode = [a-zA-Z0-9] Then 'Blah
Ok, let's see if I can make this make sense. I have a program
How can I make this work? switch(property.PropertyType){ case typeof(Boolean): //doStuff break; case typeof(String): //doOtherStuff
How can I make this java generic cast ? public interface IField { }
How can I make this input transparent? <input type=text class=foo> I've tried this but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.