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

  1. #1

    Default SQL Help please

    Hi I'm having a bit of problem with my SQL code, I would appreciate some help.
    I need to output a product ID, Name, short description etc and also the
    images.. the images are held in a seperate table like this I have a table with
    basically.. Product ID Image type Image Name
    100_____1_________image_Small.jpg 100_____2_________image_medium.jpg
    100_____3_________image_large.jpg 101_____1_________image_Small.jpg
    101_____2_________image_medium.jpg 101_____3_________image_large.jpg I need
    images for each product where the image type is EQ to 2 or 3. Now I can't pull
    both filenames into the same field, so I would have to make new fields for the
    imagename.. like imagemedium and imagelarge. The following statement does what
    I need if I only wanted one picture with the image type of 2. I wrote a
    subquery but it brought back more than one line of data.. so I didn't do that
    one right! Select distinct tbl_skus.sku_productid, tbl_products.product_name,
    tbl_products.product_shortdescription, tbl_prdtimages.prdctimage_filename,
    tbl_skus.sku_price, tbl_products.product_stockstatus from (tbl_skus inner join
    tbl_products on tbl_skus.sku_productID = tbl_products.product_ID) inner join
    tbl_prdtimages on tbl_products.product_ID = tbl_prdtimages.prdctImage_productID
    where tbl_products.product_onweb = '1' and tbl_products.product_siteid = '9'
    and tbl_prdtimages.prdctimage_imgtypeid = '2' order by
    tbl_products.product_name Thanks for help, Dan

    Stormpool Guest

  2. #2

    Default Re: SQL Help please

    This is going to be dependant upon which db your using, but

    and tbl_prdtimages.prdctimage_imgtypeid IN (2,3)

    Or using sub query

    Select columns
    from table T1 Inner Join (Select ProductId, ImageName From ImageTable Where
    ImageType = 2) T2 On T1.ProductId = T2.ProductId

    Then you can just add another inner join for type 3.

    Plus there are a number of other ways, but it depends on the db.

    Ken


    The ScareCrow Guest

  3. #3

    Default Re: SQL Help please

    Using an SQL db, I tried the 'and tbl_prdtimages.prdctimage_imgtypeid IN
    (2,3)' Just to check it's output, andit gives the product twice where there
    are two images, which I didn't want to do. Actually I definately can't do that
    because the two types of images are in different locations and when I output
    the data to a CSV if they are using the same field heading you won't know what
    Location they are in.

    Stormpool Guest

  4. #4

    Default Re: SQL Help please

    You still did not indicate which db your using. There are a lot of sql db's

    Actually I definately can't do that because the two types of images are in
    different locations and when I output the data to a CSV if they are using the
    same field heading you won't know what Location they are in.

    How do you intend to get the location, if it's not in the db ??

    Even though there are 2 records returned (which is what should be returned,
    because there are 2 images), the recordset can still be output correctly using
    cf.

    Do some research on the "group" attribute of the cfoutput tag.

    Ken

    The ScareCrow 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