Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining two tables using SQL-SELECT 1

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have two tables with the same record structure : ENTS with 1235 records and ARCS with 16,800 records. How can I use SELECT SQL to create a single cursor with all 18035 records.

I realise there is some information in the VFP Help files, but if anyone has written or can recommend a short guide to the very basic features of SELECT-SQL in VFP, with a a few simple examples, that would be very helpful.

Thanks - Andrew Mozley
 

Hi,

[pre]SELECT * FROM ENTS UNION ALL SELECT * FROM ARCS INTO CURSOR result[/pre]

mJindrova
 
You explicitly asked for SQL, and there's nothing to add to that.

I welcome the interest in SQL, but what's more important in a datbase system than the discussion about xbase commands vs sql is that same structured data points out it should be in one table, so why would you not merge the tables by APPEND? You could append one to the other table. The two names point out that one group of records is about different things. I don't think you mean Ents from the world of Lord of the Rings, but if there is a general difference between the one and the other then you could record that in a new logical field.

Chriss
 
You might not use append if the structures were different - you could end up with just a bunch of blank records or ruin
the referential integrity if you had duplicate keys.


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Good advice, at least about the duplicate keys.

AndrewMozley said:
I have two tables with the same record structure

Well, when you want to add a field like lArc .T. for all ARCS records and .F. foir all ENTS, you'd create an empty table with that field as last field, DEFAULT .F. or no default, which causes .F. as default anyway, no primary key constraint, append in the ARCS records and REPLACE ALL lArc WITH .T., then append all ENTS records. And finally either renumber all IDs, if there is such a field or introduce one and add in the primary key constraint or candidate key for free tables can have no primary key constraint.

Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top