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

  1. #1

    Default MySQL Query Problem

    :confused;

    What is wrong with the following Query? It's in the book, but not working.

    Select OrderID, OrderDate,
    (SELECT Count (*)
    From MerchandiseOrdersItems oi
    Where oi.OrderID = o.OrderID) AS ItemCount
    FROM MerchandiseOrders o
    Where ContactID = #Session.Auth.ContactID#
    ORDER By OrderDate DESC

    cf101 Guest

  2. Similar Questions and Discussions

    1. mysql++ i mysqlpp::Query problem
      Hello all! I've a problem with mysql++-2.1.1 examples. Compiler compiles properly but when I create Query object program crashes (when it is...
    2. mySQL query writing problem
      I have a table with a dozen or so fields. I am trying to return all 12 fields in all records that contain an entry in the field named 'week'. This...
    3. Query problem moving from mysql 4 to 5
      I am currently developing a website that is used to display college course information. I have everything running exactly as intended on my server...
    4. PHP/MySQL Query Problem in Dreamweaver
      I am trying to retrieve data from mysql database using php code in Dreamweaver. It is a simple query that is supposed to list all entries from...
    5. Problem with MySQL Query
      Problem with mySQL Query This is the query I have: $dbqueryshipping1 = "select * from tempuserpurchase where...
  3. #2

    Default Re: MySQL Query Problem

    but not working

    Does it give an error, return nothing, what ?

    What book ?

    Can you use sub selects with mySQL ?

    Ken
    The ScareCrow Guest

  4. #3

    Default Re: MySQL Query Problem

    The book is ColdFusion MX by Ben Forta Nate Weiss
    Error Message is:
    Syntax error or access violation: You have an error in your SQL syntax near
    'SELECT Count (oi.OrderID) From MerchandiseOrdersItems oi Where oi.OrderID ' at
    line 2




    Originally posted by: The ScareCrow
    but not working

    Does it give an error, return nothing, what ?

    What book ?

    Can you use sub selects with mySQL ?

    Ken



    cf101 Guest

  5. #4

    Default Re: MySQL Query Problem

    If you are using an "older" version of MySql (before 4.1.x), then you can not perform subselects in your queries.

    Phil
    paross1 Guest

  6. #5

    Default Re: MySQL Query Problem

    I'm new at this too, but is there a problem using the alias "o.OrderID" before
    it is declared in the next line? What if you used the regular table name
    "MerchandiseOrders.OrderID" instead?

    I may be completely off base, but it just sets off an alrm to me when you use
    something before it is declared. :confused;

    d_adams Guest

  7. #6

    Default Re: MySQL Query Problem

    The problem with the query is this code
    (SELECT Count (*)
    From MerchandiseOrdersItems oi
    Where oi.OrderID = o.OrderID) AS ItemCount

    As I suspect that the version of mySQL being used does not allow sub selects

    Ken

    The ScareCrow Guest

  8. #7

    Default Re: MySQL Query Problem

    Assuming you're using a version of mySQL that supports subqueries (mySQL 4.1.?
    or higher)...

    Just remove the space between Count and (*).

    --- Tested with mySQL 4.1.9
    SELECT OrderID, OrderDate,
    (SELECT Count(*)
    FROM MerchandiseOrdersItems oi
    WHERE oi.OrderID = o.OrderID) AS ItemCount
    FROM MerchandiseOrders o
    WHERE ContactID = #Session.Auth.ContactID#
    ORDER By OrderDate DESC

    mxstu Guest

  9. #8

    Default Re: MySQL Query Problem

    Hi guys!
    It looks like old versions of MySQL do not support Sub Select quiries.


    cf101 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