Query selecting from 2 two tables

  • I have two tables
    table 1 and table 2 i want to select distinct records from both these tables and load into main table.

    How to write the query?

  • Do all the tables have an identical structure? Doing a UNION removes all duplicates from a dataset so...
    INSERT INTO MainTable
    SELECT *
    FROM Table1
    UNION
    SELECT *
    FROM Table2;

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Yes, all 3 tables has same structure.
    we are having 2 packages, in one package we are loading table 1 data in another package we are loading table 2 data.

    but we are planning to call package 2 in package1..so that they will be as one. and in last state planning to load from these two tables into main table.
    in both these table1 and table 2 there may be some duplicates.. that's why planning to do distinct..is that works? or the way which you mentioned using union works?

  • Yes the union will work, just the union without a union all will do a distinct on the entire result set.

Viewing 4 posts - 1 through 3 (of 3 total)

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