SQL Select causing multiples...

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

  1. #1

    Default SQL Select causing multiples...

    I hate to bother with this, as I have had this issue before and solved it - But
    I cannot remember what I did! I have t tables, a member list (with ID) and a
    email table (with ID keyed to the member table). I am using the email table as
    a boolean to allow emails to those members. If their ID exists in the email
    table, its a yes... So in my control panel I have 2 queries, one for the
    opt-ins:
    <!---Get OPT-INS--->
    <cfquery datasource="#DSN#" name="optin">
    SELECT distinct
    #SESSION.ID.area#members.ID,#SESSION.ID.area#EMAIL .ID,#SESSION.ID.area#members.b
    usName
    FROM #SESSION.ID.area#members, #SESSION.ID.area#EMAIL
    WHERE #session.ID.area#members.ID=#session.ID.area#EMAIL .ID
    ORDER BY #SESSION.ID.area#members.busName
    </cfquery>

    which works fine, and one for OPT-OUTs;

    <!---Get OPT-OUTS--->
    <cfquery datasource="#DSN#" name="optout">
    SELECT DISTINCT
    #SESSION.ID.area#members.ID,#SESSION.ID.area#EMAIL .ID,#SESSION.ID.area#members.b
    usName
    FROM #SESSION.ID.area#members, #SESSION.ID.area#EMAIL
    WHERE #SESSION.ID.area#members.ID<>#SESSION.ID.area#EMAI L.ID
    ORDER BY #SESSION.ID.area#members.busName
    </cfquery>

    Which DOES NOT work as planned...

    What the OPT-OUT query does is check the email table for a match against EACH
    ID, so if I have 10 OPT-IN's in the email table, the OPT-OUT result for EACH
    mamber is repeated 10 times. Basically I need the OPT-OUT query to simply show
    a list of members who's ID nuber does NOT appear in the email table.

    bigbrain28 Guest

  2. Similar Questions and Discussions

    1. Multiples adapters with flashcomm
      I want to use multiple adapter with different IP address in each one, so I will make sure that one application is working in one IP and another...
    2. #25474 [Bgs]: posting arrays from a select box with multiple select is not working properly
      ID: 25474 User updated by: fmuller at cisco dot com -Summary: apache2filter: posting from a multiple select box is not...
    3. #25474 [Fbk->Opn]: posting arrays from a select box with multiple select is not working properly
      ID: 25474 User updated by: fmuller at cisco dot com Reported By: fmuller at cisco dot com -Status: Feedback...
    4. set up a datagrid of multiples datatables in 1 dataset
      I have a few tables consisting two columns each. They all have the same first column (unique key) What I want to do is show a datagrid, starting...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default Re: SQL Select causing multiples...

    >simply show a list of members who's ID nuber does NOT appear in the email table

    One method is to use a subquery

    SELECT memberID FROM tableOne WHERE memberID NOT IN (SELECT memberID from
    tableTwo)

    ... or a left join ...

    SELECT t1.memberID
    FROM tableOne t1 LEFT JOIN tableTwo t2 ON t1.memberID = t2.memberID
    WHERE t2.memberID IS NULL

    * not tested

    mxstu Guest

  4. #3

    Default Re: SQL Select causing multiples...

    Awesome! That first method worked perfectly. Thanks so much for the quick response, you are a lifesaver!
    bigbrain28 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