Mysql Update + SELECT query

combinations, mysql, select

Solution

You query won't work because you're asking for exams that have id = 1 AND id = 2.

Assuming that id cannot hold two values at the same time, you'll never return any results.

Try this as the basis of your update instead :-

SELECT * FROM exams
WHERE score >= 80 AND id IN ( '1','2' )

Edited based on comment :-

User wants only people who scored more than 80 for both exams. Assuming personid is a key to the person who took the exam.

SELECT e1.personid FROM
(
   SELECT personid FROM exams  WHERE score >= 80 AND id = '1' 
) e1
INNER JOIN
(
   SELECT personid FROM exams  WHERE score >= 80 AND id = '2' 
) e2
ON
  e1.personid = e2.personid

Problem

I want to update data table for those who score exam id 1,2 more than 80. I try this ``` UPDATE data SET column = 'value' WHERE (SELECT * FROM exams WHERE (id = '1' AND score >= 80) AND (id = '2' AND score >= 80)); ``` It gives me 0 result. But it should have few hundreds results ANy help?? I think the problem is this: ``` SELECT * FROM exams WHERE (id = '1' AND score >= 80) AND (id = '2' AND score >= 80) ``` It gives 0 result. How to select those who score more than 80 points for both exam 1 and 2??

Original source