Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2005
    Posts
    2

    Unanswered: Tricky merge, how to query data from 2 tables

    Hi!

    This is a question how to create a query. I have 2 tables, suppose tab1 and tab2, with almost the same structure and field names:

    tab1 (
    firstname1 varchar(20),
    lastname1 varchar(20),
    paid1 number,
    datetime1 date)

    tab2 (
    firstname2 varchar(20),
    lastname2 varchar(20),
    paid2 number,
    datetime2 date)

    I have to create a view, that gets the data (select *) from tab1 if datetime1 before Jan 7, 2005 and the data (select *) from tab2 if datetime2 after Jan 7, 2005.
    This view should return the result table like (firstname,lastname,paid,datetime)

    Is it possible to query DB that way?

    Thank you.

    Alex.

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Yes, try using UNION (read it the manual).

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    Jun 2004
    Location
    Liverpool, NY USA
    Posts
    2,509
    select firstname1,
    lastname1,
    paid1,
    datetime1
    from tab1
    where datetime < to_date('Jan 7, 2005','dd-mon-yyyy')
    union all
    select firstname2,
    lastname2,
    paid2,
    datetime2
    from tab2
    where datetime >= to_date('Jan 7, 2005','dd-mon-yyyy');
    Bill
    You do not need a parachute to skydive. You only need a parachute to skydive twice.

  4. #4
    Join Date
    Feb 2005
    Posts
    2
    Thank you!

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    See, nothing 'tricky' about using UNION.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •