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

  1. #1

    Default Re: query problem

    SELECT top5.PRODID, p.PRODNAME
    FROM (
    SELECT TOP 5 SALES = COUNT(*), PRODID
    FROM SALES
    GROUP BY PRODID
    ORDER BY SALES DESC ) AS top5
    INNER JOIN PRODUCTS p ON p.PRODID = top5.PRODID

    ORDER BY top5.SALES DESC

    --
    Tony Rogerson
    SQL Server MVP
    [url]http://www.sqlserverfaq.com?mbr=21[/url]
    (Create your own groups, Forum, FAQ's and a ton more)


    Tony Rogerson Guest

  2. Similar Questions and Discussions

    1. Query problem, please help.
      mysql Ver 12.22 Distrib 4.0.24, for pc-linux-gnu (i386) gives me: The following database Error occured: You have an error in your SQL syntax....
    2. ***Sql Query problem
      Randy Webb wrote: SELECT DISTINCT OrderID FROM trans WHERE Trans_ID = 1 AND OrderID NOT IN (SELECT DISTINCT OrderID FROM trans WHERE Trans_ID =...
    3. Query of Query problem
      Error Executing Database Query. Query Of Queries runtime error. Table named "DATA" was not found in Memory. It is misspelled, or the table is...
    4. Query on Query and CF casting problem
      I am using a custom tag in MX7 that was working fine in 5 that renders a table. The input to the custom tag is a query and it's columns along with...
    5. Query problem.
      column 1 column2 column 3 column 4 1 current 1.0 yr1 1 previous ...
  3. #2

    Default Re: query problem

    SELECT TOP 5 P.PRODNAME, COUNT(*) AS total_sales
    FROM PRODUCTS P
    INNER JOIN SALES s
    ON P.PRODID = s.PRODID
    GROUP BY P.PRODNAME
    ORDER BY total_sales DESC

    --
    Jacco Schalkwijk MCDBA, MCSD, MCSE
    Database Administrator
    Eurostop Ltd.


    "He Sha" <hesha@hotmail.com> wrote in message
    news:eE5k3w4RDHA.3700@tk2msftngp13.phx.gbl...
    > Hi all,
    >
    > There is a table called SALES with a single field called PRODID. An entry
    is
    > made into this everytime there is a sale.
    >
    > Doing a SELECT TOP 5 COUNT(*) C, PRODID FROM SALES GROUP BY PRODID ORDER
    BY
    > C DESC gives me the list of top 5 selling products.
    >
    > In another table PRODUCTS, there are two fields PRODID, PRODNAME. Is there
    a
    > way to find out the names of top 5 selling products using a single query?
    >
    > Thanks,
    > HS.
    >
    >
    >

    Jacco Schalkwijk Guest

  4. #3

    Default query problem

    Hi all,

    There is a table called SALES with a single field called PRODID. An entry is
    made into this everytime there is a sale.

    Doing a SELECT TOP 5 COUNT(*) C, PRODID FROM SALES GROUP BY PRODID ORDER BY
    C DESC gives me the list of top 5 selling products.

    In another table PRODUCTS, there are two fields PRODID, PRODNAME. Is there a
    way to find out the names of top 5 selling products using a single query?

    Thanks,
    HS.



    He Sha Guest

  5. #4

    Default Query Problem

    I have 2 tables, each which contain usernames and id's.

    I need to extract all users from tableA which do not appear in tableB but
    cant figure out the syntax of the query.

    Any Ideas ?

    Thanks in advance


    Poppy Guest

  6. #5

    Default Re: Query Problem

    "Poppy" <paul.diamond@NOSPAMthemedialounge.com> wrote in message
    news:OJTpog69DHA.4020@TK2MSFTNGP09.phx.gbl...
    > I have 2 tables, each which contain usernames and id's.
    >
    > I need to extract all users from tableA which do not appear in tableB
    but
    > cant figure out the syntax of the query.
    >
    > Any Ideas ?
    Database? Version? DDL? Sample Data?

    Here's a pseudo query since I have no idea what your database looks
    like:

    SELECT
    A.username,
    A.id
    FROM
    tableA AS A LEFT JOIN
    tableB AS B ON
    A.username = B.username AND
    A.id = B.id
    WHERE
    B.id IS NULL

    HTH
    -Chris Hohmann



    Chris Hohmann Guest

  7. #6

    Default Re: Query Problem

    And you can use Not In within a query:

    [url]http://dbforums.com/showthread.php?postid=3050009#post3050009post30500 09[/url]

    Best regards,
    J. Paul Schmidt, Freelance ASP Web Developer
    [url]http://www.Bullschmidt.com[/url]
    ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bullschmidt Guest

  8. #7

    Default Re: query problem

    When you use Order_By, you must include all fields from your query. You can use the MS Access Upsize tool OR use SQL Server Enterprise Manager Database Tranformation Services (DTS).

    -- lnh
    tejun Guest

  9. #8

    Default Re: query problem

    thx for your answer.

    Do you know where i can get basic info on how to migrate from access to sql
    server?
    do i need to change the code of the queries contained in my cfm and cfc files?
    what are these changes ???



    newuser111 Guest

  10. #9

    Default Query problem

    I have 2 seperate queries:

    1)
    select *
    from vendor
    left outer join model
    on vendor.PID=model.VendorID
    left outer join specs
    on model.Model=specs.ProdModel
    where vendor.Vendor='#URL.Vendor#'
    order by Model

    2)
    SELECT specs.SpecID
    from vendor
    left outer join model
    on vendor.PID=model.VendorID
    left outer join specs
    on model.Model=specs.ProdModel
    where vendor.Vendor='TGB'

    So, why am I getting a error saying that a 'element SPECID is undefined in
    specs' when it works with query #2 when I put:

    select *, specs.SpecID
    from vendor
    left outer join model
    on vendor.PID=model.VendorID
    left outer join specs
    on model.Model=specs.ProdModel
    where vendor.Vendor='#URL.Vendor#'
    order by Model


    Steve Grosz Guest

  11. #10

    Default Re: Query problem

    Steve Grosz wrote:
    > So, why am I getting a error saying that a 'element SPECID is undefined in
    > specs' when it works with query #2 when I put:
    >
    > select *, specs.SpecID
    > from vendor
    > left outer join model
    > on vendor.PID=model.VendorID
    > left outer join specs
    > on model.Model=specs.ProdModel
    > where vendor.Vendor='#URL.Vendor#'
    > order by Model
    Just a quick guess, but have you tried specifying the tables in your *
    select? e.g. select vendor.*, specs.SpecID from vendor ... I'd give
    that a shot first and see if that makes any difference.

    Matt

    --
    Matt Woodward
    Team Macromedia - ColdFusion
    mpwoodward *TMM* Guest

  12. #11

    Default Re: Query problem

    So, if I enter it like this:

    <cfquery name="test" datasource="Test3">
    select
    specs.ProdImage,model.Model,specs.ProdStroke,specs .ProdCC,specs.ProdFuel,
    specs.SpecID
    from vendor
    left outer join model
    on vendor.PID=model.VendorID
    left outer join specs
    on model.Model=specs.ProdModel
    where vendor.Vendor='#URL.Vendor#'
    order by Model

    I still have the same problem. A 'Element SPECID is undefined in SPECS'
    error message

    Steve
    "mpwoodward *TMM*" <mpwoodward@gmail.com> wrote in message
    news:d4e0vm$gc6$1@forums.macromedia.com...
    > Steve Grosz wrote:
    >> So, why am I getting a error saying that a 'element SPECID is undefined
    >> in specs' when it works with query #2 when I put:
    >>
    >> select *, specs.SpecID
    >> from vendor
    >> left outer join model
    >> on vendor.PID=model.VendorID
    >> left outer join specs
    >> on model.Model=specs.ProdModel
    >> where vendor.Vendor='#URL.Vendor#'
    >> order by Model
    >
    > Just a quick guess, but have you tried specifying the tables in your *
    > select? e.g. select vendor.*, specs.SpecID from vendor ... I'd give that
    > a shot first and see if that makes any difference.
    >
    > Matt
    >
    > --
    > Matt Woodward
    > Team Macromedia - ColdFusion

    Steve Grosz 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