There is a table:

  • students: id, name, surname;
  • disciplines: id, name;
  • marks: id, s_id, d_id, t_id, value.

You need to create a linked subquery that lists the names of students who have grades 3 and 4 at the same time. Did so:

SELECT id, name, surname FROM students WHERE 3 or 4 IN (SELECT value FROM marks WHERE marks.st_id = students.id GROUP BY marks.st_id); 

This query will display all students, even those who do not have any marks at all. If or replace with and will display the right person. But doesn’t AND mean that there should be an error, because the value cannot be simultaneously 3 and 4.

screenshot: enter image description here

  • Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky

1 answer 1

 SELECT id, name, surname FROM students S WHERE 2=(select count(distinct value) from marks M where M.st_id=S.id and M.value IN(3,4) ) 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nicolas Chabanovsky