vetrnicek
vetrnicek

Reputation: 73

Sql query doesn't work in Mysql version 5.5.16

I am attempting to execute the following query:

$query = "SELECT O. * AS NUM FROM (ab_order O)
    LEFT JOIN ab_user U ON (O.id_user=U.id)
    WHERE O.id IN ( SELECT OT.id_ab_order FROM ab_order_transaction OT
        LEFT JOIN ab_transaction T ON (OT.id_ab_transaction = T.id)
    LEFT JOIN ab_user U ON (T.id_user = U.id) 
    WHERE T.validated = 1 {$condTrans} ) {$condOrder}
    ORDER BY {$orderCol} LIMIT $from, $numRecords ";
$queryDB = $DB->queryExec($query);

On the live server:

But I need to use localhost:

On localhost it says:

MySQL error: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS NUM
FROM (ab_order O)
LEFT JOIN ab_u' at line 1.

Is any easier way then uprgrade the live server Mysql database?

Upvotes: 2

Views: 351

Answers (2)

Moyed Ansari
Moyed Ansari

Reputation: 8461

You can define Alias for individual column in SELECT. Here is the issue

SELECT O. * AS NUM

Instead of this use

SELECT O. * 

This is useful article Using Column Alias in SELECT Statement

Upvotes: 1

Mark Wilkins
Mark Wilkins

Reputation: 41222

The aliasing of all the columns seems incorrect: SELECT O. * AS NUM. I'm unsure of why it would work on previous versions, but the as num should either be removed, or each column should be explicitly aliased.

Upvotes: 2

Related Questions