sql >> Database teknologi >  >> RDS >> Mysql

MINUS operator i MySQL?

En NOT IN() underforespørgsel kan bruges her, da MySQL ikke understøtter MINUS .

SELECT 
  cand_email
FROM tbl_cand_data 
WHERE can_email NOT IN (SELECT un_email FROM tbl_unsubscribe)

Det kan også gøres med en LEFT JOIN , leder efter NULL i un_email kolonne:

SELECT cand_email 
FROM
   tbl_cand_data
   LEFT JOIN tbl_unsubscribe ON tbl_cand_data.can_email = tbl_unsubscribe.un_email
WHERE tbl_unsubscribe.un_email IS NULL

For at ekskludere dem fra en masse UNION operationer, skal du ombryde UNION gruppe i () som en underforespørgsel:

SELECT email FROM (
  SELECT cand_email AS email FROM tbl_cand_data
  UNION
  SELECT emp_email AS email FROM tbl_emp_data
  UNION
  SELECT email FROM AS email tbl_uptade_list
  UNION
  SELECT feed_email AS email FROM tbl_feedback
  UNION
  SELECT admin_email AS email FROM tbl_admin_emails
) email_list
WHERE email NOT IN (SELECT un_email FROM tbl_unsubscribe)


  1. Fejl:kunne ikke initialisere masterinformationsstrukturen under udførelsen af ​​Master Slave Replikering i MySQL

  2. MYSQL GROUP BY og ORDER BY arbejder ikke sammen som forventet

  3. PHP-MySQL-Hvordan øges MySQL-heltalsfeltet sikkert?

  4. Java lagret procedure kalder i java program