insert values only if they do not already exist in table

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default insert values only if they do not already exist in table

    Hello I want to insert some values from one table (A) into another table (b).
    However there are some values in table A which exist two times in table A. I
    only want to insert values one time. So If a certain field value also exist in
    some other row (same fieldname) then I don't want to insert it twice. It
    doesn't matter which of the two rows will be inserted.

    Can this be done with MySQL? Maybe with some Control Flow Functions?

    Hopefully someone can help me.

    Thank you in advance.

    Gr, Kabbi

    kabbi~thkek Guest

  2. Similar Questions and Discussions

    1. How Do you insert a table in Previous Table
      How Do you insert a table in Previous Table that has an image, in a web page
    2. Login - multi table insert for registrant; subsquent login insert page requests into joined 'Selection' Table
      Question regards insert and updates in sql server for a simple login script that requires registration the first time and only "email address" upon...
    3. insert values in an array
      Hy all, I like to insert a value in an array but only want to renumber the ones after the inserted value like this; situation 1)...
    4. table does not exist error in AD query?
      this runs perfectly as a .vbs but I'd like to convert it to an ASP... any ideas? Response.Buffer = True Dim objConnection, objCommand,...
    5. TEMP table comes into exist very slow
      I have a piece of code like this SELECT SUM(col1) c1 From tbl GROUP BY col2 INTO TEMP tmp_tbl WITH NO LOG; Select AVG(c1) FROM tmp_tbl; My...
  3. #2

    Default Re: insert values only if they do not already exist intable

    use the keyword distinct in your select clause.
    Dan Bracuk Guest

  4. #3

    Default Re: insert values only if they do not already exist intable

    Hi Dan Bracuk,

    Thank you for your answer! I already have another question about this. I also
    do not want to insert values from A into B if they already exist in B.

    I believe this should also be possible, do you perhaps know how?

    Grt, Kabbi

    kabbi~thkek Guest

  5. #4

    Default Re: insert values only if they do not already exist intable

    Hi,

    I used DISTINCT, however I now only get the values for that specific row I
    used the distinct for (without any duplicates!!). However I want to get all
    data(all columns) from a row but only the rows for where there is no duplicate
    item in column G

    SELECT *
    FROM inventimport WHERE DISTINCT G

    Will not work I guess?



    kabbi~thkek Guest

  6. #5

    Default Re: insert values only if they do not already exist intable

    I want to get all data(all columns) from a row but only the rows for where
    there is no duplicate item in column G
    A quick idea to get you started:



    <cfquery name="myQuery1" datasource="myDSN">
    SELECT G, count(*) as G_frequency
    FROM inventimport
    GROUP BY G
    </cfquery>

    <cfquery name="myQuery2" dbtype="Query">
    SELECT G
    FROM myQuery1
    WHERE G_frequency < 2
    </cfquery>

    <cfquery name="myQuery3" datasource="#application.dsn#">
    SELECT *
    FROM inventimport
    WHERE G in (#QuotedValueList(myQuery2.G)#)
    </cfquery>

    BKBK Guest

  7. #6

    Default Re: insert values only if they do not already exist intable

    Originally posted by: kabbi~thkek
    Hi,

    I used DISTINCT, however I now only get the values for that specific row I
    used the distinct for (without any duplicates!!). However I want to get all
    data(all columns) from a row but only the rows for where there is no duplicate
    item in column G

    SELECT *
    FROM inventimport WHERE DISTINCT G

    Will not work I guess?



    I said your select clause, not your where clause.

    Dan Bracuk Guest

  8. #7

    Default Re: insert values only if they do not already exist intable

    :) yes, thank you!!
    kabbi~thkek Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139