Beginner: Copying one field of a table into another

Discussions

General J2EE: Beginner: Copying one field of a table into another

  1. Beginner: Copying one field of a table into another (3 messages)

    Does SQL allow me to copy one field of a table to be inserted into another table?
    I am thinking something along the following lines:
    [code]
    INSERT INTO TableTwo (
    field_one,
    field_two,
    field_three,
    field_four
    )

    VALUES (
    'value_one',
    SELECT field_x FROM TableOne,
    -- or --
    SELECT * FROM TableOne WHERE some_field = 'something',
    'value_three',
    'value_four'
    );
    [/code]
    From what I have read, INSERT SELECT places one row of one table into another.
    However, i have not seen anything that covers inserting a single field in the same manner.

    Many thanks in advance for your assistance.
  2. Hi leo rio ,

    You can do this as long as your sub-query ,

    "SELECT field_x FROM TableOne"

    or

    "SELECT * FROM TableOne WHERE some_field = 'something'"

    Returns only 'one' ROW ( actullay 'one' VALUE).

    Cheers,
    @bhijit
  3. Ooops!

    What's wrong with:

    insert TableTwo
      select 'value one',field_x,'value three','value four'
      from TableOne
      where some_filed = 'something';
  4. Nothing !

    But question was about 'inserting a single field'.

    Cheers,
    @bhijit