I'm looking to find the exact-matches columns that have the same answers to a set of the same questions. Their answers may vary, and I want to find the ones where two people answered the same, and I want to get their unique response ID.
SELECT
response
FROM
responses_questions
WHERE (
SELECT
answer
FROM
responses_questions
WHERE
response = '$my_response_id'
GROUP BY
question
ORDER BY
question
ASC
) = (
SELECT
answer
FROM
responses_questions
GROUP BY
question
ORDER BY
question
ASC
)
I'm completely aware that the query above will NOT work.
The primary problem is that I need to compare the "criteria query" (consists of several rows) to the rest of the database to return the response ID for the matching groups of columns. Basically, for each question, I need all of their answers to be the same as the "example" query that we are comparing to. "Comparing two subqueries".
I can easily visualize the data I need to get; Nonetheless, SQL doesn't take into account what us humans "visualize"...
If I need to provide more information, please let me know in the comments below.
EDIT: Screenshot/More Data
Here is a screenshot of some example data:
The highlighted data is what we are SELECTING in the "first" part of my query above. I need to find all of the data that MATCHES.
My expected output should be the following numbers from the response
column: 5
and 7
. But not 6
.
Keep in mind: There will be hundreds of questions, so a lot more rows to "compare". Therefore, don't hard-code any specific question numbers in.