how can I join 2 tables into a new table

  • I would like to take 2 tables and join them

    both tables are exactly the same except for the file name

    ie stochist and stoctran

    i want a file that will have both current and histoy data in them

    many thanks

    Larry

  • Hi,

    Can you share more info.

    Regards,

    Prajey

  • Larry,

    Going to need a lot more information here, see the 'How to post...' link in my sig below for some help.

  • Based on the limited information you have provided you need to look up the JOIN statement in BOL here, or Google it here

  • Both tables have exactly the same fields but different record data and tried this!!

    select * from stoctran

    union all

    select * from stochist

    but does not give me all the data from both tables ???

    I am using a DB manager program to do the SQL script and allows me to save the data created into a file.

    eg stoctran.dat

    code description txdate qnty price

    xyz widget 10/5/01 10 34.60

    xyz widget 15/5/01 5 34.60

    abc icon 16/5/01 9 10.50

    stochist.dat

    code description txdate qnty price

    xyz widget 10/5/98 7 32.60

    xyz widget 15/5/99 5 33.60

    abc icon 10/01/01 4 9.50

    what result I want is

    code description txdate qnty price

    xyz widget 10/5/01 10 34.60

    xyz widget 15/5/01 5 34.60

    abc icon 16/5/01 9 10.50

    xyz widget 10/5/98 7 32.60

    xyz widget 15/5/99 5 33.60

    abc icon 10/01/01 4 9.50

  • Don't see why that wouldn't give you all records from both tables, that's exactly what 'UNION ALL' does.

    What makes you think is not returning all records ?

    Can you do a COUNT on the individual tables and compare the totals to the total number of records in the union?

  • hi Nigel

    thats the bitch... stochist has about 15,000 records and stoctran has about 400

    but all that is being returned is 35 records and cannot understand why.

    tables are not corrupted.

    The database is DBIsam and using dbsys.exe manager from elevate software.

    to be honest very much a newbie with SQL and do not work much with it.

  • Ah, not SQL Server then. Your best bet then is the elevate software website.

  • their website sucks and also an old version of the software that is no longer supported but SQL is still SQL, just the syntax is different between different vendors.

    any how will battle on

    thanks for taking the time to respond

  • Larry Coe (10/19/2010)


    their website sucks

    Ahh! typical. Sorry I couldn't be of more help.

    As you say SQL is SQL (maybe!). 🙂

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply