具有内部联接"LIMIT"子查询的错误语法



我正在尝试执行一个子查询。出于某些目的(我必须使用js库DataTables来处理数据(,我需要在查询中放入一个子查询。但当我尝试这样做时,我会遇到语法错误。

基本上,我有两张表:

片剂

WW_PS_ORDERS

| id_order| reference| total_paid| date_add| id_cart|
|:------- |:--------:| ---------:| -------:| ------:|
| 1       | ABCDEF   | 10        |2022-01-01| 15

智能

| ID_PS| identificativo_ordine|
|:-    |:--------------------:| 
| 15    |  ABCDJEHR          |

因此,为了获得第一个表的所有字段和第二个表的字段"identificationvo_ordine",我提出了这个请求:

SELECT en.id_order, en.reference, en.total_paid, en.date_add, 
s.identificativo_ordine, en.id_cart
from develettronw.ww_ps_orders en 
inner join smarty.orders s on en.id_order = s.id_ps
order by en.date_add desc

但理想情况下,我需要做这样的事情:

SELECT id_order, 
reference,total_paid,date_add,identificativo_ordine,id_cart 
FROM (
SELECT en.id_order, en.reference, en.total_paid, 
en.date_add, s.identificativo_ordine, en.id_cart
from develettronw.ww_ps_orders en 
inner join smarty.orders s on en.id_order = s.id_ps
)

但我得到了一个";语法错误";由LIMIT引起,但我的请求中没有LIMIT。为什么?

#1064-错误di sintassi nella查询SQL vicino a‘LIMIT 0,25’第5行

。。大致翻译为

#1064-sql查询中靠近"limit 0 25"第5行的语法错误

MySQL客户端正在尝试自动对结果进行分页。该查询首先无效,分页查询也无效。您的查询将抛出:

每个派生表都必须有自己的别名

。。。因为您忘记定义子查询的别名。应该是:

SELECT id_order, 
reference,total_paid,date_add,identificativo_ordine,id_cart 
FROM (
SELECT en.id_order, en.reference, en.total_paid, 
en.date_add, s.identificativo_ordine, en.id_cart
from develettronw.ww_ps_orders en 
inner join smarty.orders s on en.id_order = s.id_ps
) some_alias_here --> You missed this

附加LIMIT具有掩盖实际误差的副作用。

最新更新