Access substitute for EXCEPT clause

前端 未结 4 1170
有刺的猬
有刺的猬 2020-12-07 01:36

How can I get the same result I would get with the SQL code below in ms access? It does not recognize the EXCEPT clause...

SELECT DISTINCT 
             


        
相关标签:
4条回答
  • 2020-12-07 01:55

    Not an explicit example here, but consider UNION-ing the two fetched tables and selecting, from that union, pairs that have fewer than 2 instances of a certain field combination. This implies that, where each table has more than one instance of a record with the same values on the field combination, these records are the same and can be eliminated from result set. Where not, they are unique to one table, leaving fetch with only records from the selected table where there is no match to the other table. Kind of like a poor-man's "EXCEPT" KW.

    0 讨论(0)
  • 2020-12-07 02:07
    SELECT A.x FROM A
    EXCEPT
    SELECT B.x FROM B
    

    corresponds to

    SELECT A.x FROM A 
    LEFT JOIN B 
    ON A.x = B.x 
    WHERE B.x IS NULL
    
    0 讨论(0)
  • 2020-12-07 02:09

    use the find unmatched wizard in MS Access > Create > Query Wizard and you will get the following result

    Union is a separate Access Query which i used to union a few tables instead of using sub queries

    SELECT TableMain.Field1
    FROM TableMain LEFT JOIN [Union] ON TableMain.[Field1] = Union.[field1]
    WHERE (((Union.field1) Is Null));
    
    0 讨论(0)
  • 2020-12-07 02:14

    In order to get rid of the EXCEPT you could combine the conditions and negate the second one:

    SELECT DISTINCT 
           P.Name, 
           T.Training
      FROM Prof AS P, 
           Training_done AS TC, 
           Trainings AS T
     WHERE ((P.Name Like '*' & NameProf & '*') AND
            (P.Primary_Area = T.Cod_Area)) 
       AND NOT ((P.Name Like '*' & NameProf & '*') AND
                (P.Cod_Prof = TC.Cod_Prof));
    
    0 讨论(0)
提交回复
热议问题