Convert Sub Query to Group

Hi, is it possible to convert this extra request into a connection?

SELECT staff_no
FROM doctor
WHERE NOT EXISTS (SELECT *
                  FROM patient
                  WHERE staff_no = consultant_no);
+3
source share
2 answers
SELECT  staff_no
FROM    doctor
LEFT JOIN
        patient
ON      staff_no = consultant_no
WHERE   consultant_no IS NULL

To be effective, consultant_noindex and declare how NOT NULL.

If this is not the case, select any column declared as NOT NULLa patient’s and replace it consultant_nowith this column in the section WHERE.

See this blog post for a comparison of the three methods for this query in MySQL:

+7
source
   SELECT staff_no
     FROM doctor
LEFT JOIN patient
       ON staff_no = consultant_no
    WHERE consultant_no IS NULL
+3
source

Source: https://habr.com/ru/post/1718801/


All Articles