If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > What's wrong with this statement??

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-17-03, 11:08
big_poppa big_poppa is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Question What's wrong with this statement??

Can someone please show me how to re-write this statement for MySQL? I wrote it in Access using the wysiwyg and then copied the SQL. I get a very generic error when I run it, however and cannot figure out what is wrong. I can usually write my own statements, but when I get too many JOINS, I get confused.

I'd appreciate any help.

SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.* FROM (customers INNER JOIN orders ON customers.custID = orders.ocustomerid) INNER JOIN (products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.orderID = oitems.orderid WHERE (((orders.orderID)=2))
Reply With Quote
  #2 (permalink)  
Old 10-17-03, 11:57
bstjean bstjean is offline
Registered User
 
Join Date: Sep 2002
Location: Montreal, Canada
Posts: 219
Re: What's wrong with this statement??

Quote:
Originally posted by big_poppa
Can someone please show me how to re-write this statement for MySQL? I wrote it in Access using the wysiwyg and then copied the SQL. I get a very generic error when I run it, however and cannot figure out what is wrong. I can usually write my own statements, but when I get too many JOINS, I get confused.

I'd appreciate any help.

SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.* FROM (customers INNER JOIN orders ON customers.custID = orders.ocustomerid) INNER JOIN (products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.orderID = oitems.orderid WHERE (((orders.orderID)=2))
FROM tablename INNER...

NOT

FROM (tablename INNER ...
Reply With Quote
  #3 (permalink)  
Old 10-17-03, 12:39
big_poppa big_poppa is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Re: What's wrong with this statement??

I removed the first set of parenthesis:

SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.* FROM customers INNER JOIN orders ON customers.custID = orders.ocustomerid INNER JOIN (products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.orderID = oitems.orderid WHERE (((orders.orderID)=2))

But I still get this vague message:

You have an error in your SQL syntax near '(products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.'

which is where the error was ocurring before as well
Reply With Quote
  #4 (permalink)  
Old 10-17-03, 13:35
bstjean bstjean is offline
Registered User
 
Join Date: Sep 2002
Location: Montreal, Canada
Posts: 219
Re: What's wrong with this statement??

Quote:
Originally posted by big_poppa
I removed the first set of parenthesis:

SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.* FROM customers INNER JOIN orders ON customers.custID = orders.ocustomerid INNER JOIN (products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.orderID = oitems.orderid WHERE (((orders.orderID)=2))

But I still get this vague message:

You have an error in your SQL syntax near '(products INNER JOIN oitems ON products.catalogID = oitems.catalogid) ON orders.'

which is where the error was ocurring before as well
INNER JOIN (products
same thing..
should be
INNER JOIN products
Reply With Quote
  #5 (permalink)  
Old 10-17-03, 13:44
big_poppa big_poppa is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Re: What's wrong with this statement??

yeah, i had tried that after your last suggestion. I tried a bunch of different groupings hoping to hit on something, but no luck

You have an error in your SQL syntax near 'INNER JOIN oitems ON products.catalogID = oitems.catalogid ON orders.orderID = o'
Reply With Quote
  #6 (permalink)  
Old 10-17-03, 14:59
bstjean bstjean is offline
Registered User
 
Join Date: Sep 2002
Location: Montreal, Canada
Posts: 219
Re: What's wrong with this statement??

Quote:
Originally posted by big_poppa
yeah, i had tried that after your last suggestion. I tried a bunch of different groupings hoping to hit on something, but no luck

You have an error in your SQL syntax near 'INNER JOIN oitems ON products.catalogID = oitems.catalogid ON orders.orderID = o'
I'm not sure about what you want to do but could you format your query like this... Would make it clearer to you and everyone else...


SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.*

FROM customers

INNER JOIN orders ON customers.custID = orders.ocustomerid
INNER JOIN products ON ??????????????????????
INNER JOIN oitems ON (products.catalogID = oitems.catalogid and orders.orderID = orderid )

WHERE orders.orderID=2


Looks like someth
Reply With Quote
  #7 (permalink)  
Old 10-17-03, 15:59
big_poppa big_poppa is offline
Registered User
 
Join Date: Oct 2003
Posts: 6
Re: What's wrong with this statement??

you, my friend, are a genius!

I think this worked (at least I didn't receive any errors). I now just need to verify that I'm getting the correct values I was looking for. Here's what I am using now:

SELECT orders.orderID, orders.*, products.ccode, products.cname, products.cprice, oitems.numitems, customers.*
FROM customers
INNER JOIN orders ON customers.custID = orders.ocustomerid
INNER JOIN products ON oitems.catalogid = products.catalogID
INNER JOIN oitems ON (products.catalogID = oitems.catalogid and orders.orderID = oitems.orderid )
WHERE orders.orderID=2

Thank you so much for looking at this for me. Just looking at this last way that you structured it has actually given me a better understanding of what this query is really doing. Thanks again!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On