Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL select question
Message
De
31/03/2008 12:33:58
 
 
À
30/03/2008 20:04:08
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01306837
Message ID:
01307011
Vues:
11
I also thought of a UNION rather than a join. However, I think your solution may be imcomplete since he is asking for all records rather than all PK's. My assumption is that the table have identical structures (if not, the code needs to be modified to select specific fields). My try would be
SELECT * FROM table1;
    UNION;
SELECT * FROM table2 WHERE pk NOT IN (SELECT pk FROM table1)
>Unlike Nadya's solution, your description of the problem makes me immediately think of a UNION. That is, I think of JOIN more in the sense of horizontally combining tables; and UNION in the sense of combining tables vertically.
>
>
>select PkField from Table1;
>  UNION select PkFIeld from Table2;
>  into cursor Tmp
>
>
>Note that, if you don't specify a DISTINCT clause, duplicates will be eliminated automatically.
>
>It seems to me, however, that Nadya's approach is just as sound, and that you could do it either way. My sample represents my personal preference in this case.
>
>>Hi everybody,
>>
>>I am struggling to create one SQL select that will create a query as following (simplified):
>>
>>
>>1. table mytable1 has the following records:
>>
>>PK_VAL
>>1
>>2
>>3
>>
>>2. table mytable2 has the following records:
>>PK_VAL
>>1
>>2
>>5
>>6
>>
>>
>>I want to create a query of all records in mytable1 plus records in mytable2 that have PKs missing in mytable1. In the example above, the resulting query would have the following records:
>>
>>PK_VAL
>>1  (from mytable1)
>>2  (from mytable1)
>>3  (from mytable1)
>>5  (from mytable2)
>>6  (from mytable2).
>>
>>
>>Thank you in advance for any help.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform