Sql query doesn't work in Mysql version 5.5.16 - mysql

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:
it works with MySql version 3.3.10.
PHP version 5.2.17.
But I need to use localhost:
XAMPP for linux, v. 1.7.7
PHP 5.3.8
MySql version 5.5.16.
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?

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.

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

Related

What is wrong with this MySQL command?

The query that is throwing an error for my MySQL DB is:
SELECT t1.GROUPNAME FROM user_group t0, group t1 WHERE ((t0.users_USERNAME =
?) AND (t1.GROUPNAME = t0.groups_GROUPNAME))
The error info is the following:
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 'group t1 WHERE
((t0.users_USERNAME = 'test') AND (t1.GROUPNAME = t0.groups_GROUP')
Okay so I know the problem is with the group t1 part. But I dont know what is wrong with it.
Click here to see that I have all the needed colums
Can any one find out what the problem could be here?
group is a reserved word in SQL. You should put quotes around it.
Some JPA providers do that automatically, whereas others don't ...

SQL execution error

I try this query
INSERT INTO shop.product(prod_id,model,desc) SELECT product.id_prod,prod_lang.name,product.ref from product left join product_lang on product_lang.id_prod = product.id_prod
However I got this error
SQL execution error # 1065.Response from the database:
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') SELECT product.id_prod,product_lang.name,product.ref from' at line 1
Two problems:
DESC is a reserved keyword. Use backquote (``) for desc.
Change prod_lang to product_lang in the query.
Solution:
INSERT INTO shop.product (prod_id,model,`desc`)
SELECT product.id_prod,product_lang.name,product.ref
from product left join
product_lang on product_lang.id_prod = product.id_prod
Note:
It is a good practice to use backquotes for all columns eventhough it is not a reserved keyword.

Syntax error in MySQL Join Query

I'm getting a syntax error in MySQL query. Is MySQL and SQL server work differently? Can anyone suggest, what is wrong and where ?
select b.component, d.matter, d.bug, d.timestamp, d.os
from bugs.profiles p, ops_reports.BPR_TAG_DATA d
left join (Select * from bugs where product='test') b
on d.bug=b.bug_id
where d.tagid = 6
and timestamp between "2014-04-21" and "2014-04-24"
and login_name like 'test'
and p.userid = d.user
Error Message 24/04/2014 23:14:10 0:00:00.037 MySQL Database Error: 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 'Select * from bugs where product='Conversions') as b
on (d.bu 1 0
You should not mix implicit and explicit joins. A simple rule: just don't use commas in the from clause.
select b.component, d.matter, d.bug, d.timestamp, d.os
from ops_reports.BPR_TAG_DATA d left join
bugs b
on b.product = 'test' and d.bug = b.bug_id left join
bugs.profiles p
on p.userid = d.user
where d.tagid = 6 and
timestamp between '2014-04-21' and '2014-04-24' and
login_name like 'test';
I also removed the subquery, moving the condition to the on clause. This makes the query more efficient. And changed the delimiters for the date constants to single quotes. Using double quotes for strings can lead to confusion.
EDIT:
All this said, the query in the question looks like it is syntactically correct. I notice that the error message does not refer to this exact query. The query has product='test') b and the error message has product='Conversions') as b. Perhaps there are other differences as well.

MySQL select with alias

i have error on sql statment
SELECT temp.* FROM
(SELECT th1.process_id,th2.process_id FROM `thread` as th1,`thread` as th2
where (th1.thread_id=th2.thread_id)and
(th1.process_id!=th2.process_id) and
(th1.analysis_id='".$analysis_id."' ) and
(th2.analysis_id='".$analysis_id."' )) as temp
where ((t emp.p1 NOT IN (select pr.parent_process_id from process as pr
wherer pr.process_id=th2.process_id and (th2.analysis_id='".$analysis_id."' )
and (pr.analysis_id='".$analysis_id."' )))
or (temp.p2 NOT IN
(select pr1.parent_process_id from process as pr1
wherer pr1.process_id=th1.process_id and (th2.analysis_id='".$analysis_id."' )
and (pr1.analysis_id='".$analysis_id."' ))))
You have an obvious syntax error using wherer instead of where.
wherer pr.process_id=th2.process_id and
Should be
where pr.process_id=th2.process_id and
When MySQL reports an error similar to Check the manual for the correct syntax to use near..., look exactly to that location or to the character immediately before it for your syntax error.
check the manual that corresponds to your MySQL server version for the right syntax to use near 'wherer pr.process_id=tem.p2

Mysql join 2 database and 3 tables query?

SELECT db1_t1.userid as userid
, db1_t1.customer_id as vw_customer
, db2_t1.customers_id as customer
, db2_t1.orders_id as order
FROM database1.table1 db1_t1
LEFT JOIN database2.table1 db2_t1
ON db1_t1.customer_id = db2_t1.customers_id
It gives me this error:
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 'order FROM
database1.table1 db1_t1 LEFT JOIN
database2.' at line 2
I am using php and mysql.
order is a keyword - think ORDER BY my_column.
I'd suggest renaming it, but you could enclose it in backticks
db2_t1.orders_id AS `order`