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

  1. #1

    Default inequality question

    I'm having trouble trying to run a query that returns rows that don't match.
    The code below returns all the matching rows but what I need is all the image
    names in the excelImages table that don't match the images in the
    imagesOnServer table. Using the <> operator results in an error. Thanks for
    any help on this.

    <cfquery datasource="imagesDB" name="compare">
    SELECT excelImages.imagename
    FROM excelimages
    INNER JOIN ImagesOnServer
    ON excelImages.imagename = ImagesonServer.images
    </cfquery>

    megalith Guest

  2. Similar Questions and Discussions

    1. Testing a variable for inequality
      What i'm doing is: if a searched term is not found in the database, it will redirect the user back to the search page. However, here is my problem,...
    2. Checking inequality
      I have the following code in one of my trigger functions --------------------------------------------------------------- IF...
  3. #2

    Default Re: inequality question

    syntax varies with databases but you want to do something like
    select imagename
    from excelimages
    where imagename not in
    (select images from imagesonserver)
    Dan Bracuk Guest

  4. #3

    Default Re: inequality question

    Thanks Dan.
    I always forget to mention the DB. For this I am using Access. I tried this
    code and it resulted in my CPU hanging at 95%. Nothing that a quick resart of
    CF wouldn't fix. Any different approach for Access? thanks again for your
    reply.

    SELECT imagename
    FROM excelimages
    WHERE imagename NOT IN
    (SELECT Images
    FROM ImagesOnServer)


    megalith Guest

  5. #4

    Default Re: inequality question

    Hi
    try this:

    <cfquery datasource="imagesDB" name="compare">
    SELECT excelImages.imagename
    FROM excelimages
    LEFT JOIN ImagesOnServer
    ON excelImages.imagename = ImagesonServer.images
    </cfquery>
    vkunirs Guest

  6. #5

    Default Re: inequality question

    Thanks vkunirs but that returns all the images. What I need is all the excelimages that aren't in the imagesonserver table. Anyone else have an idea for me? thanks
    megalith Guest

  7. #6

    Default Re: inequality question

    <cfquery datasource="imagesDB" name="compare">
    SELECT e.imagename
    FROM excelimages e
    WHERE NOT EXISTS (SELECT 1
    FROM ImagesOnServer i
    WHERE e.imagename = i.images)
    </cfquery>

    Phil
    paross1 Guest

  8. #7

    Default Re: inequality question

    Hi

    try by giving the where condition.

    <cfquery datasource="imagesDB" name="compare">
    SELECT excelImages.imagename
    FROM excelimages
    LEFT JOIN ImagesOnServer
    ON excelImages.imagename = ImagesonServer.images
    where excelImages.imagename <> ImagesonServer.images
    </cfquery>

    if still this does not work then try with MINUS.
    like

    select * from table1
    minus
    select * from table2.


    vkunirs Guest

  9. #8

    Default Re: inequality question

    Srinivas, I'm curious how you would expect a query to return any rows where
    excelImages.imagename = ImagesonServer.images and excelImages.imagename <>
    ImagesonServer.images at the same time.

    Phil ;)

    paross1 Guest

  10. #9

    Default Re: inequality question

    Thanks Phil but even that didn't seem to work. After 10 minutes I gave up
    waiting and restarted the windows swsoc.exe service and the CF database
    service. It showed no signs of stopping. One table has 27,500 rows and the
    other had 26,800. Not sure if that's so big that this type of query should take
    so long.

    Anyways, since I had the equality working I decided to backup the DB and then
    just run a DELETE all where records matched. I was then left with the records I
    have been trying to get at.

    I would still like to find a query that will do what we have been trying to
    do. Thanks everyone for your efforts on this.

    megalith Guest

  11. #10

    Default Re: inequality question

    Try adding an index to the imagename field in the excelimages table, and the images field in the imagesonserver table (if one does not exist).

    Phil
    paross1 Guest

  12. #11

    Default Re: inequality question

    Phil,
    One table had an index already but the other didn't. I added the index to the
    other table, ran your query, and it finished in about 10 minutes. Seems strange
    that it can run the equality query in 1 second but the inequality takes 10
    minutes?

    Either way I appreciate your help and everyone elses. I now know how to write
    the query, I just have to be very patient for an answer from the DB.

    megalith Guest

  13. #12

    Default Re: inequality question

    Glad that this worked for you, although 10 minutes is still way too long to
    have to wait for a query to run, especially if this is online.

    When was the last time that you performed a repair and compact on your
    database? I used to have an application that used an Access database, and when
    the db file got over approximately 30 MB in size, my queries would ground to a
    halt after a data import until I would run compact. (I finally migrated it to
    SQL Server, since Access tends to get squirrelly when it reaches certain size
    limits, etc.)

    Phil

    paross1 Guest

  14. #13

    Default Re: inequality question

    Phil,

    10 minutes does seem way too long to me also. the select statement for
    equality runs in 1 second. The Access DB is only 3mb and it has indexes and
    was compacted and repaired before I ran the query. Kinda strange. I wonder if
    using MySQL would make a difference. Maybe if I have some spare time I will
    convert it to MySQL and give it a try. Thanks for your input.

    megalith Guest

  15. #14

    Default Re: inequality question

    First let me explain why <> is so slow.
    It is because the DB must scan the indices (or even the table) completely for
    every "left term" row.

    In essence you lose most of the benefits of indices!
    This is not an Access problem, it is true of all RDBMS.

    That said, the attached query should be more efficient:



    <CFQUERY datasource="imagesDB" name="compare">
    SELECT
    excelImages.imagename
    FROM
    excelimages
    LEFT JOIN
    ImagesOnServer ON excelImages.imagename = ImagesonServer.images
    WHERE
    ImagesonServer.images IS NULL
    </CFQUERY>

    MikerRoo Guest

  16. #15

    Default Re: inequality question

    MikerRoo,

    That did the trick. The query took 2 seconds to run and came back with the correct quantity. Thanks for the code!
    megalith 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