简体   繁体   中英

SELECT statement using LEFT JOIN

I've got a table that is periodically updated in Access.

This table is very simple, composed of 2 Columns. I will represent them with 2 identifiers: Column Operadora and column NDC. One Operadora may have N NDC.

This table is permanent, and 2 operations are done every single day to it: A DELETE to all columns and an APPEND, done from a linked table that comes from a .txt (that is updated every day).

I need to capture differences between the table that exists before it is appended: The values that are present in it but are not in the "new" version of the linked table, AND The values that are not present in it but are in the "new" version of the linked table.

I've managed to find a way of doing this with a LEFT JOIN using some examples, but not with my tables indeed. My table has many values (something like 1000) to be compared, and it is returning only the column names for the SELECT above, even though the same select returns the values i want with another examples.

Here is my SELECT sample to try finding the first part of the problem (values that are present in the table but not in the linked table), so anyone can help me finding the problem:

SELECT [1A - NDC_MSISDN].Operadora, [1A - NDC_MSISDN].NDC
FROM [1A - NDC_MSISDN] LEFT JOIN [Linked NDC MSISDN TXT] ON [1A - NDC_MSISDN].[Operadora] = [Linked NDC MSISDN TXT].[Operadora]
WHERE ((([Linked NDC MSISDN TXT].Operadora) Is Null));

PS:

1A - NDC_MSISDN -> Fixed table to be compared (with values "999999")
Linked NDC MSISDN TXT -> Linked table to be compared (without values "999999")

Linked NDC MSISDN TXT:

Operadora;NDC_MSISDN
A;491
A;492
A;493
A;494
A;495
A;496
A;497
A;498
A;499
A;490
A;770005
B;71
C;82
D;50
E;980
F;385
G;303
G;308
G;402
G;620
G;719
G;785
G;758
G;970
H;9
H;70100
H;70101
H;70102
H;70103
H;801
H;802
H;80769
H;8077
H;8078
H;80790
H;80791
H;80792
H;808
H;8092
H;8095
H;8099
H;9010
H;90111
H;90112
H;9014
H;9015
H;9016
H;90187
H;90188
H;90189
H;90198
H;90199
H;9021
H;9022
H;9023
H;9024
H;9025
H;9026
H;9027
H;9030
H;9031
H;9032
H;9033
H;90340
H;90346
H;90347
H;90348
H;90349
H;9040
H;90411
H;90412
H;90413
H;90414
H;9043
H;9045
H;9046
H;9047
H;9048
H;9049
H;905
H;90669
H;90676
H;90677
H;90678
H;90679
H;90680
H;90681
H;90682
H;90684
H;90688
H;90689
H;9069
H;9070
H;9071
H;9072
H;9073
H;9074
H;9076
H;9077
H;9078
H;9079
H;90800
H;90801
H;90802
H;90803
H;90841
H;90842
H;90857
H;90858
H;90859
H;90863
H;90864
H;90865
H;90866
H;90867
H;90868
H;90869
H;9087
H;9088
H;9089
H;9090
H;9095
I;400
I;401
I;404
I;406
I;408
I;409
I;410
I;411
I;414
I;415
I;416
I;417
I;418
I;419
I;453
I;456
I;457
I;458
I;459
I;461
I;462
I;465
I;466
I;468
I;469
I;470
I;471
I;474
I;475
I;476
I;477
I;478
I;479
I;480
I;481
I;482
I;483
I;484
I;485
I;488
I;489
I;580000
I;5800020
I;58000210
I;5800030
I;5800041
I;5800042
I;5800050
I;5800076
I;580010
I;590
I;591
I;592
I;595
I;900
I;901
I;902
I;903
I;904
I;905
I;906
I;907
I;908
I;909
I;910
I;911
I;912
I;913
I;914
I;915
I;916
I;917
I;918
I;919
I;921
I;923
I;925
I;927
I;929
I;931
I;933
I;935
I;937
I;939
I;940
I;941
I;943
I;944
I;945
I;947
I;948
I;949
I;950
I;951
I;952
I;953
I;954
I;955
I;956
I;957
I;958
I;959
I;960
I;961
I;962
I;963
I;964
I;965
I;966
I;967
I;968
I;969
I;970
I;971
I;972
I;973
I;974
I;975
I;976
I;977
I;979
I;983
I;985
I;987
I;989
I;990
I;991
I;992
I;993
I;994
I;995

1A - NDC_MSISDN (With "999999" added to each operadora to exemplify):

Operadora;NDC_MSISDN
A;491
A;492
A;493
A;494
A;495
A;496
A;497
A;498
A;499
A;490
A;770005
A;9999999
B;71
B;9999999
C;82
C;9999999
D;50
D;9999999
E;980
E;9999999
F;385
F;9999999
G;303
G;308
G;402
G;620
G;719
G;785
G;758
G;970
G;999999
H;9
H;70100
H;70101
H;70102
H;70103
H;801
H;802
H;80769
H;8077
H;8078
H;80790
H;80791
H;80792
H;808
H;8092
H;8095
H;8099
H;9010
H;90111
H;90112
H;9014
H;9015
H;9016
H;90187
H;90188
H;90189
H;90198
H;90199
H;9021
H;9022
H;9023
H;9024
H;9025
H;9026
H;9027
H;9030
H;9031
H;9032
H;9033
H;90340
H;90346
H;90347
H;90348
H;90349
H;9040
H;90411
H;90412
H;90413
H;90414
H;9043
H;9045
H;9046
H;9047
H;9048
H;9049
H;905
H;90669
H;90676
H;90677
H;90678
H;90679
H;90680
H;90681
H;90682
H;90684
H;90688
H;90689
H;9069
H;9070
H;9071
H;9072
H;9073
H;9074
H;9076
H;9077
H;9078
H;9079
H;90800
H;90801
H;90802
H;90803
H;90841
H;90842
H;90857
H;90858
H;90859
H;90863
H;90864
H;90865
H;90866
H;90867
H;90868
H;90869
H;9087
H;9088
H;9089
H;9090
H;9095
H;9999999
I;400
I;401
I;404
I;406
I;408
I;409
I;410
I;411
I;414
I;415
I;416
I;417
I;418
I;419
I;453
I;456
I;457
I;458
I;459
I;461
I;462
I;465
I;466
I;468
I;469
I;470
I;471
I;474
I;475
I;476
I;477
I;478
I;479
I;480
I;481
I;482
I;483
I;484
I;485
I;488
I;489
I;580000
I;5800020
I;58000210
I;5800030
I;5800041
I;5800042
I;5800050
I;5800076
I;580010
I;590
I;591
I;592
I;595
I;900
I;901
I;902
I;903
I;904
I;905
I;906
I;907
I;908
I;909
I;910
I;911
I;912
I;913
I;914
I;915
I;916
I;917
I;918
I;919
I;921
I;923
I;925
I;927
I;929
I;931
I;933
I;935
I;937
I;939
I;940
I;941
I;943
I;944
I;945
I;947
I;948
I;949
I;950
I;951
I;952
I;953
I;954
I;955
I;956
I;957
I;958
I;959
I;960
I;961
I;962
I;963
I;964
I;965
I;966
I;967
I;968
I;969
I;970
I;971
I;972
I;973
I;974
I;975
I;976
I;977
I;979
I;983
I;985
I;987
I;989
I;990
I;991
I;992
I;993
I;994
I;995
I;999999

The output I want with the select is:

A;999999
B;999999
C;999999
D;999999
E;999999
F;999999
G;999999
H;999999
I;999999

My guess is that you're only joining on one column, but looking for variability in both columns. So, try updating your join clause:

SELECT [1A - NDC_MSISDN].Operadora, [1A - NDC_MSISDN].NDC
FROM [1A - NDC_MSISDN]
  LEFT JOIN [Linked NDC MSISDN TXT]
    ON [1A - NDC_MSISDN].[Operadora] = [Linked NDC MSISDN TXT].[Operadora]
      AND [1A - NDC_MSISDN].[NDC] = [Linked NDC MSISDN TXT].[NDC]
WHERE (([Linked NDC MSISDN TXT].Operadora) Is Null);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM