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

mysql :Vis ikke duplikatresultat på SELECT

Desværre skal du udføre de to øverste forespørgsler to gange for at fjerne dem fra den nederste forespørgsel:

SELECT p.*, 1 as enabled
    FROM member_permissions mp
    JOIN permissions p ON p.permission_id = mp.permission_id
    WHERE member_id = 1
UNION
    SELECT pgp.*, 1 as enabled
    FROM member_permissions mp
    JOIN permission_link pl ON pl.permission_group_id = mp.permission_group_id
    JOIN permissions pgp ON pgp.permission_id = pl.permission_id
    WHERE member_id = 1
UNION
    SELECT *, 0 as enabled
    FROM permissions p where p.permission_id not in (
      SELECT p.permission_id
          FROM member_permissions mp
          JOIN permissions p ON p.permission_id = mp.permission_id
          WHERE member_id = 1
      UNION ALL
      SELECT pgp.permission_id
          FROM member_permissions mp
          JOIN permission_link pl ON pl.permission_group_id = mp.permission_group_id
          JOIN permissions pgp ON pgp.permission_id = pl.permission_id
          WHERE member_id = 1
   )


  1. Opret en pivottabel med PostgreSQL

  2. Operand bør indeholde 1 kolonne - MySQL NOT IN

  3. Magento:Tilføj produktattributter med modulinstallationsscript

  4. Filtrer resultater efter dato i tidsstempelfeltet