I am trying to pair two arrays in MySQL. They should match only by its index. Meaning that if a = 1, b = 2, and c = 3, the array(1,2,3) would match against array(a,b,c) and return 1,2,3, while (b,a,c) won’t. Which should only return ‘3’.
My code
I have two arrays which I am sending to the SQL server. The first is the ids of the questions I am answering. The second is the answers.
I have done this:
SELECT
id, title
FROM
`questions` q
WHERE
q.id IN (2, 4) AND q.answer IN ('Christoffer Columbus', 'Arnold Schwarzenegger')
;
… This checks if id 2 equals ‘Christoffer Columbus’ AND ‘Arnold Schwarzenegger’. So if you answer ‘Christoffer Columbus’ on both question 1 and 2, it will be correct. That’s not so good… 🙂
Can you help me with this one? How do I solve this?
I think you’re looking for this:
You need to add a similar criteria for each pair from the arrays.