Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Current and History Data
Message
From
12/04/2005 10:43:43
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
12/04/2005 10:37:32
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01003742
Message ID:
01003748
Views:
17
>I have the need to create a SQL statement that pulls data from payroll check current and history files. These files a VFP 6.0 free tables with exactly the same structure. These tables also do not include a unique key. The problem is if I issue a statement such as "select * from G:\Sbtpr\PRAXIS\prchck01,G:\Sbtpr\PRAXIS\prhchk01 into cursor tccursor" the computer slows to a crawl and eventually I get an error message stating the bla bla bla temp file is too large. If I change the SQL statement to only pull from on file at a time there are now issues at all. Separately it is actually quite fast. If I specify specific fields in the combined statement I get an error stating that the first field requested in not unique. I am sure this is because the same field name exists in both tables. Can I have one SQL Statement to pull data from both files?

Your statement above will combine every record from table A, with every record from table B. For example, if each table has 10,000 records, you will get a total of 100 million records in your result. This is the reason it is taking a long time. This is called a "Cartesian product", which is usually created by accident, and the results are usually very big and very wrong. (However, there are also legal uses for a Cartesian product - I use it now and then.)

To combine "vertically" your two tables, i.e. add one to the end of the other, what you need is a UNION.
select Field1, Field2, Field3 from TableA;
  union select Field1, Field2, Field3 from TableB;
  order by 2;
  into cursor Temp
Note that: (1) The structure of the two parts has to be identical, (2) ORDER BY is only possible by number, as above.

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform