In MySQL, how can I find all rows whose attribute1 is the same as a particular row’s attribute1? I thought about doing
SELECT
t1.id
FROM
t AS t1
, t AS t2
WHERE
t2.id=123
AND t1.a=t2.a;
but it has been running for eons.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
This should work to return the required rows.
How many rows are in your table? Is the “a” column indexed? Adding an index should speed up the join.
Here’s an example on SQLFiddle.