Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    2

    Unanswered: Joining two tables

    I have two tables:
    1. Incomes
    Income Amount
    Salary 10000
    Sales 55000
    and 2. Expenses

    Expense Amount
    House Rent 3000
    Tution 4000
    Fooding 4000
    Travelling 2000

    I want to join these to tables to form:
    Salary 10000 Expense Amount
    Sales 55000 House Rent 5000
    (null) (null) Tution 4000
    (null) (null) Fooding 4000
    (null) (null) Travelling 2000

    How can it be done. Thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    it cannot be done unless you specify some way of joining them

    in other words, what conditions would determine that

    -- Salary 10000 is matched with Expense Amount
    (seems to be a typo here -- Expense and Amount are column names, not column values)
    -- Sales 55000 is matched with House Rent 5000

    are you planning any primary keys for these tables?


    rudy
    http://r937.com/

  3. #3
    Join Date
    Feb 2002
    Posts
    2,232
    There are a couple of ways you can handle this:

    1.
    select income, amount, 'income' as type from incomes
    union
    select expense, amount, 'expense' as type from expenses
    order by type

    2.
    select income, amount, '','' from incomes
    union
    select '','',expense, amount from expenses

    Or another variation.

Posting Permissions

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