Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Location
    Argentina
    Posts
    26

    Unanswered: A more complicated case of insertion filtering by more than two fields

    Hi,

    I posted a problem some hours ago. I found that the solution that l was given by Karolyn was great, but at that time I didn't realize that my problem was a little bit more complicated. I'll rephrase my problem:

    I need to insert some registers in a table. These registers have three fileds: col1, col2 and col3. I don't want to insert a register if in the table already exists a row with the col1, col2 and col3 combination of that register. These fields are PK, but I don't want to get errors. The problem is that I'm inserting a field that belongs also to the destination table. How can I filter a "destination" table by two fields in this case?

    This the table1:

    create table table1(
    col1 int not null,
    col2 int not null,
    col3 int not null,
    constraint PK_table1 primary key (col1, col2, col3)
    )


    Here's my "insert" code:

    INSERT INTO table1
    SELECT table2.col1, table3.col2, table1.col3
    FROM table2, table3
    WHERE table2.col1 = table3.col1


    The third field in the SELECT now refers also to table1. Witch conditions should I add to avoid repetitions in table1 (avoiding also erroing)

    Thanks

    Federico

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: A more complicated case of insertion filtering by more than two fields

    Originally posted by fmilano

    INSERT INTO table1
    SELECT table2.col1, table3.col2,table1.col3
    FROM table2, table3
    WHERE table2.col1 = table3.col1

    Doesn't make sense.....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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