Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select doesn't produce expected results
Message
De
25/10/2012 14:33:21
 
 
À
25/10/2012 14:12:44
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
01555800
Message ID:
01555813
Vues:
44
Ok, you're trying to do something similar to what this does to make sure that for every record in the 'update' table, we have a matching 'convatc' and vice versa:
** this will show any update record that does not have
** a corresponding convatc record

Select a.itmnum As upitem, b.itmnum As convitem From;
   update a Left Outer Join convatc b On b.itmnum = a.itmnum;
   Into Cursor chkitms

Count To convcnt For Isnull(convitem)

If convcnt > 0
   Select upitem As itmnum, 'UPDATE' As erfil, "No Matching ConvATC Record" As remarks;
      From chkitms ;
      Where Isnull(convitem) ;
      Into Cursor missconv
Endif

** now going the other way (in Convatc, not Update)
Select a.itmnum As upitem, b.itmnum As convitem From;
   convatc b Left Outer Join Update a On a.itmnum = b.itmnum;
   Into Cursor chkitms

Count To upcnt For Isnull(upitem)

If upcnt > 0
   Select convitemas itmnum, 'CONVATC' As erfile, "No Matching Update Record" As remarks;
      From chkitms ;
      Where Isnull(upitem) ;
      Into Cursor missup
Endif
what you want to find is the null values.


>
>Thanks guys. Perhaps some more info is in order. The data in the 2 tables purports to be the same but is from different sources and so is not identical. We want to determine which is to more reliable source by comparing the 2 against each other. Each record contains address, businessname, and # of employees. So I want to produce a side by side comparison of the number of employees for each address/business match. My approach to do this is using Q3 table as a base, find the matching records in INFO without loosing any non-matching records. Hence:
>
>
>SELECT pagcleanad as infoaddress,pagbusines as infobusiness, INT((mon1_empl+mon2_empl+mon3_empl)/3) as infoemploy, ;
>emp as q3Employ, address as q3address, trade_name as q3business ;
>FROM info ;
>LEFT JOIN q3 ON pagcleanad = address AND pagbusines = trade_name
>
>
>Next I wanted to turn it around and preserve all the records from the INFO table. I expected this could be done by simply switching from a left to a right join like this.
>
>SELECT pagcleanad as infoaddress,pagbusines as infobusiness, INT((mon1_empl+mon2_empl+mon3_empl)/3) as infoemploy, ;
>emp as q3Employ, address as q3address, trade_name as q3business ;
>FROM info ;
>RIGHT JOIN q3 ON pagcleanad = address AND pagbusines = trade_name
>
>
>Note the only change is going from a LEFT to a RIGHT join. These 2 selects are then put together with a UNION ALL. I may be wrong but I believe this is producing the desired result. What surprised me was that the second select takes MUCH longer to run than the first. So as an experiment I elected to turn the second select around and make it a LEFT join which also required turning the equivalencies around. When I did this I found that this 3rd select is not equivalent to the second which is what has me confused. I had thought that
>
>LEFT JOIN q3 ON pagcleanad = address AND pagbusines = trade_name
>
>was equivalent to
>
>RIGHT JOIN q3 ON address=pagcleanad AND trade_name=pagbusines
>
>but it clearly is not. So when we talk about left and right what exactly are we talking about? Apparently it is not the order of the equivalency. If we say LEFT JOIN Q3 we are supposed to preserve all the records on the left, but which table is on the left if it is not determined by the order of the equivalency?
>
>Thanks for any further clarification. I guess I've been confused for a long time and didn't even know it.
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform