PDA

View Full Version : Is this valid mysql?


Snetty
07-15-2008, 03:57 PM
A friend of mine is helping me out with some mysql, only problem is he's never touched mysql and is instead an ms-sql expert. Can anyone tell me/us whether this is still valid mysql as I'm getting syntax errors reported.

If not, could someone offer up the equivalent mysql syntax please?

SELECT c.customerid,
c.orderidprefix,
c.business,
c.email,
c.status,
activeorders.orders
FROM customers c
LEFT JOIN
(
SELECT f.customerid,
COUNT(*) [Orders]
FROM formorders f
WHERE f.status <> 'accepted/scheduled'
AND f.completion_date < '15/07/2008'
) [activeorders]
ON c.customerid = [activeorders].customerid

Fumigator
07-15-2008, 05:03 PM
It really helps us help you when you post the actual error message. That said, the alias name you've used is in square brackets and that's not valid MySQL syntax; just use an alias name sans brackets, or use the "AS" keyword, i.e. LEFT JOIN (SELECT blah blah) AS activeorders

Snetty
07-15-2008, 05:19 PM
It really helps us help you when you post the actual error message. That said, the alias name you've used is in square brackets and that's not valid MySQL syntax; just use an alias name sans brackets, or use the "AS" keyword, i.e. LEFT JOIN (SELECT blah blah) AS activeorders

Yes my apologies.. that's the bane of my life also, customers who complain about bugs but never give you the error message. You'd think I'd have learnt by now :D

That sorted it straight away, I must admit, it was the brackets that I thought were the likely culprit but I wasn't at all sure about what they were in mysql.

Anyway, much thanks.