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

  1. #1

    Default Inner Join syntax

    I am trying to add another table to this query. tbl_orderskus
    Can anyone help me with this inner join syntax in adding the new table
    below?
    How can I modify to get this to work correctly with the three table?

    <!--- retrieve orders by date --->
    <cfquery name="rsByDate" datasource="nsstore2.mdb"
    username="#request.dsnUsername#" password="#request.dsnPassword#">
    SELECT tbl_customers.cst_FirstName, tbl_customers.cst_LastName,
    tbl_customers.cst_Zip,
    tbl_orders.order_ID, tbl_orders.order_Date, tbl_customers.cst_Address1,
    tbl_customers.cst_Address2, tbl_customers.cst_City, tbl_orders.order_State,
    tbl_customers.cst_Phone, tbl_customers.cst_email, tbl_customers.cst_ShpName,
    tbl_customers.cst_ShpAddress1, tbl_customers.cst_ShpAddress2,
    tbl_customers.cst_ShpCity,
    tbl_customers.cst_ShpZip,
    tbl_orders.order_ShipMeth_ID,
    tbl_customers.cst_Phone,
    tbl_orders.order_TransactionID,
    tbl_orders.order_SKU_ID,
    tbl_orders.orderSKU_OrderID,
    tbl_orderskus.orderSKU_SKU,
    tbl_orderskus.orderSKU_Quantity


    FROM tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID AND tbl_orderskus.ordersku_orderID
    WHERE tbl_orders.order_Date >=
    #CreateODBCDate(LSParseDateTime(FORM.StartDate))#
    AND tbl_orders.order_Date <=
    #CreateODBCDateTime(DateAdd("d",1,LSParseDateTime( FORM.EndDate)))#
    <cfif FORM.Status NEQ 0>AND order_Status = #FORM.Status#</cfif>
    ORDER BY tbl_orders.order_Date DESC
    </cfquery>

    lilbuckeye Guest

  2. Similar Questions and Discussions

    1. Is left-join faster then inner join?
      Some people said that using left-join is generally faster than inner join, is that true? Thanks...
    2. FMS Join two flv...
      Hello! I have an application where i need join two flv, this possible? Tks, Luiz
    3. Simple ANSI syntax Outer Join question
      Hello. I have an application that uses many *= and =* outer joins in its queries. In order to convert an older query into the proper syntax, I am...
    4. SQL outer join syntax error
      I'm not kidding, the only reason yesterday you didn't hear from me was because I wasn't coding, but today I am doing something quick, and yes, as...
    5. Newbie - Easy (I think) SQL Syntax Question, 3 table join
      I have three identical tables, t1, t2, t3 Each table contains a complete list of files on a particular server. One of the fields in each table...
  3. #2

    Default Re: Inner Join syntax

    The exact syntax depends on the database you are using. What column in the
    "tbl_orderskus" table corresponds to the other table(s). The basic syntax is
    something like the example below.

    --- Note - Access db's usually require parenthesis for tables in from clause
    ....
    FROM tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID
    INNER JOIN tbl_orderskus ON tbl_orderskus.ordersku_orderID =
    someTable.someColumnHere

    mxstu Guest

  4. #3

    Default Re: Inner Join syntax

    Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

    Can you tell me if there is a certain place I need to add these parenthesis
    or Do you think something else is wrong with the From clause?



    <!--- retrieve orders by date --->
    <cfquery name="rsByDate" datasource="nsstore2.mdb"
    username="#request.dsnUsername#" password="#request.dsnPassword#">
    SELECT tbl_customers.cst_FirstName, tbl_customers.cst_LastName,
    tbl_customers.cst_Zip,
    tbl_orders.order_ID, tbl_orders.order_Date, tbl_customers.cst_Address1,
    tbl_customers.cst_Address2, tbl_customers.cst_City, tbl_orders.order_State,
    tbl_customers.cst_Phone, tbl_customers.cst_email, tbl_customers.cst_ShpName,
    tbl_customers.cst_ShpAddress1, tbl_customers.cst_ShpAddress2,
    tbl_customers.cst_ShpCity,
    tbl_customers.cst_ShpZip,
    tbl_orders.order_ShipMeth_ID,
    tbl_customers.cst_Phone,
    tbl_orders.order_TransactionID,
    tbl_orderskus.orderSKU_ID,
    tbl_orderskus.orderSKU_OrderID,
    tbl_orderskus.orderSKU_SKU,
    tbl_orderskus.orderSKU_Quantity



    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID)(INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID)

    WHERE tbl_orders.order_Date >=
    #CreateODBCDate(LSParseDateTime(FORM.StartDate))#
    AND tbl_orders.order_Date <=
    #CreateODBCDateTime(DateAdd("d",1,LSParseDateTime( FORM.EndDate)))#
    <cfif FORM.Status NEQ 0>AND order_Status = #FORM.Status#</cfif>
    ORDER BY tbl_orders.order_Date DESC
    </cfquery>

    lilbuckeye Guest

  5. #4

    Default Re: Inner Join syntax

    I think Access uses parenthesis to indicate precedence, like this:

    FROM ( (Do this join first) Do this join second )

    ... so try something like this...

    FROM ((tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID)




    mxstu Guest

  6. #5

    Default Re: Inner Join syntax

    Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    operator) in query expression 'tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID'.

    Still not working....do you have any other suggestion? or Can you tell me
    where I can learn more about these join syntax's?
    Thank you.

    <!--- retrieve orders by date --->
    <cfquery name="rsByDate" datasource="nsstore2.mdb"
    username="#request.dsnUsername#" password="#request.dsnPassword#">
    SELECT tbl_customers.cst_FirstName, tbl_customers.cst_LastName,
    tbl_customers.cst_Zip,
    tbl_orders.order_ID, tbl_orders.order_Date, tbl_customers.cst_Address1,
    tbl_customers.cst_Address2, tbl_customers.cst_City, tbl_orders.order_State,
    tbl_customers.cst_Phone, tbl_customers.cst_email, tbl_customers.cst_ShpName,
    tbl_customers.cst_ShpAddress1, tbl_customers.cst_ShpAddress2,
    tbl_customers.cst_ShpCity,
    tbl_customers.cst_ShpZip,
    tbl_orders.order_ShipMeth_ID,
    tbl_customers.cst_Phone,
    tbl_orders.order_TransactionID,
    tbl_orderskus.orderSKU_ID,
    tbl_orderskus.orderSKU_OrderID,
    tbl_orderskus.orderSKU_SKU,
    tbl_orderskus.orderSKU_Quantity



    FROM ((tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID)

    WHERE tbl_orders.order_Date >=
    #CreateODBCDate(LSParseDateTime(FORM.StartDate))#
    AND tbl_orders.order_Date <=
    #CreateODBCDateTime(DateAdd("d",1,LSParseDateTime( FORM.EndDate)))#
    <cfif FORM.Status NEQ 0>AND order_Status = #FORM.Status#</cfif>
    ORDER BY tbl_orders.order_Date DESC
    </cfquery>

    lilbuckeye Guest

  7. #6

    Default Re: Inner Join syntax

    Just remove second set of parentesies in FROM section and make it like this
    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID



    CF_Oracle Guest

  8. #7

    Default Re: Inner Join syntax

    Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    operator) in query expression 'tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID'.

    The error occurred. on line 71.
    Nope, sorry still not working.
    It says the error is on line 71 maybe it is something else that is wrong but
    it works great without the new addition of the tblskus.
    ????

    <!--- retrieve orders by date --->
    <cfquery name="rsByDate" datasource="nsstore2.mdb"
    username="#request.dsnUsername#" password="#request.dsnPassword#">
    SELECT tbl_customers.cst_FirstName, tbl_customers.cst_LastName,
    tbl_customers.cst_Zip,
    tbl_orders.order_ID, tbl_orders.order_Date, tbl_customers.cst_Address1,
    tbl_customers.cst_Address2, tbl_customers.cst_City, tbl_orders.order_State,
    tbl_customers.cst_Phone, tbl_customers.cst_email, tbl_customers.cst_ShpName,
    tbl_customers.cst_ShpAddress1, tbl_customers.cst_ShpAddress2,
    tbl_customers.cst_ShpCity,
    tbl_customers.cst_ShpZip,
    tbl_orders.order_ShipMeth_ID,
    tbl_customers.cst_Phone,
    tbl_orders.order_TransactionID,
    tbl_orderskus.orderSKU_ID,
    tbl_orderskus.orderSKU_OrderID,
    tbl_orderskus.orderSKU_SKU,
    tbl_orderskus.orderSKU_Quantity



    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID

    WHERE tbl_orders.order_Date >=
    #CreateODBCDate(LSParseDateTime(FORM.StartDate))#
    AND tbl_orders.order_Date <=
    #CreateODBCDateTime(DateAdd("d",1,LSParseDateTime( FORM.EndDate)))#
    Line 71 <cfif FORM.Status NEQ 0>AND order_Status = #FORM.Status#</cfif>
    ORDER BY tbl_orders.order_Date DESC
    </cfquery>

    lilbuckeye Guest

  9. #8

    Default Re: Inner Join syntax

    >Can you tell me where I can learn more about these join syntax's?

    Access documentation / help files ;-)
    mxstu Guest

  10. #9

    Default Re: Inner Join syntax

    lilbuckeye,

    My mistake. A cut and paste job gone awry. It should be:

    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON tbl_orders.order_Id =
    tbl_orderskus.ordersku_OrderID

    ... instead of ...


    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orders ON tbl_orders.order_ ID =
    tbl_orderskus.ordersku_OrderID


    mxstu Guest

  11. #10

    Default Re: Inner Join syntax

    :D

    You are so Awesome!
    Thank you so much, it is working!
    lilbuckeye Guest

  12. #11

    Default Inner Join Syntax

    I can't seem to figure out these inner join syntax -
    I want to add :

    INNER JOIN tbl_skus ON tbl_skus.sku_Id = tbl_orderskus.ordersku_sku

    to the following:

    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON tbl_orders.order_Id =
    tbl_orderskus.ordersku_OrderID

    and I am getting this error:
    Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC
    Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    operator) in query expression 'tbl_orders.order_Id =
    tbl_orderskus.ordersku_OrderID INNER JOIN tbl_skus ON tbl_skus.sku_Id =
    tbl_orderskus.ordersku_sku'.

    Below is how I have it written: Can anyone please help in adding the new inner
    join without getting the syntax error?

    FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON tbl_orders.order_Id =
    tbl_orderskus.ordersku_OrderID INNER JOIN tbl_skus ON tbl_skus.sku_Id =
    tbl_orderskus.ordersku_sku

    lilbuckeye Guest

  13. #12

    Default Re: Inner Join Syntax

    It looks like you are using Access why don't you just let Access build it
    for you. In the query design view just drag the field you want to join to
    the other table / field and then right click on the link and you can adjust
    it from there.


    "lilbuckeye" <webforumsuser@macromedia.com> wrote in message
    news:draha3$6i8$1@forums.macromedia.com...
    >I can't seem to figure out these inner join syntax -
    > I want to add :
    >
    > INNER JOIN tbl_skus ON tbl_skus.sku_Id = tbl_orderskus.ordersku_sku
    >
    > to the following:
    >
    > FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    > tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON
    > tbl_orders.order_Id =
    > tbl_orderskus.ordersku_OrderID
    >
    > and I am getting this error:
    > Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC
    > Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    > operator) in query expression 'tbl_orders.order_Id =
    > tbl_orderskus.ordersku_OrderID INNER JOIN tbl_skus ON tbl_skus.sku_Id =
    > tbl_orderskus.ordersku_sku'.
    >
    > Below is how I have it written: Can anyone please help in adding the new
    > inner
    > join without getting the syntax error?
    >
    > FROM (tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    > tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON
    > tbl_orders.order_Id =
    > tbl_orderskus.ordersku_OrderID INNER JOIN tbl_skus ON tbl_skus.sku_Id =
    > tbl_orderskus.ordersku_sku
    >

    Rick Guest

  14. #13

    Default Re: Inner Join Syntax

    Access is rather particular about the placement of the parentheses in these
    JOIN statements, so you should try to play around with different combinations
    until you arrive at one that works. As a last resort, since you are doing all
    inner joins, you might try the pre-ANSI 92 SQL syntax below where you "join"
    the tables in the WHERE clause. At least this will tell you if your query is
    returning the desired results.

    FROM tbl_customers, tbl_orders, tbl_orderskus, tbl_skus
    WHERE tbl_customers.cst_ID = tbl_orders.order_CustomerID
    AND tbl_orders.order_Id = tbl_orderskus.ordersku_OrderID
    AND tbl_skus.sku_Id = tbl_orderskus.ordersku_sku

    Phil

    paross1 Guest

  15. #14

    Default Re: Inner Join Syntax

    Thanks to all for your responses!

    I found someone who knows Access much better than I do and I think we have it
    sorted out.
    FROM ((tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON tbl_orders.order_ID =
    tbl_orderskus.orderSKU_OrderID) INNER JOIN tbl_skus ON
    tbl_orderskus.orderSKU_SKU = tbl_skus.SKU_ID

    Thanks Again!:D

    lilbuckeye Guest

  16. #15

    Default Re: Inner Join Syntax

    I used to do it in Access and Copy/Paste back into CF until I learned the
    trick, now i pretty much do them on the fly.

    When adding another Join add another set of parenthesis totally surrounding
    what's already there (at the top).

    FROM ((tbl_customers INNER JOIN tbl_orders ON tbl_customers.cst_ID =
    tbl_orders.order_CustomerID) INNER JOIN tbl_orderskus ON tbl_orders.order_Id =
    tbl_orderskus.ordersku_OrderID)
    INNER JOIN tbl_skus ON tbl_skus.sku_Id = tbl_orderskus.ordersku_sku




    JMGibson3 Guest

  17. #16

    Default Re: Inner Join Syntax

    Now that I can understand how to do.
    Thanks so much for posting and sharing.
    The next time I need to do this I will know what to do.
    :-)
    lilbuckeye 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