Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的sql:您的sql语法有错误;查看与您的MySQL服务器版本对应的手册,以了解要使用的正确语法_Php_Mysql - Fatal编程技术网

Php 我的sql:您的sql语法有错误;查看与您的MySQL服务器版本对应的手册,以了解要使用的正确语法

Php 我的sql:您的sql语法有错误;查看与您的MySQL服务器版本对应的手册,以了解要使用的正确语法,php,mysql,Php,Mysql,我有这样的疑问 select c.*,j.pict from mst020 a inner join mst022 c on c.mst020_id = a.id left join (select e.pict as pict from mst021 e where e.line_number = (select max(f.line_number) from mst021 f where f.mst020_id = a.id) and e.mst020_id

我有这样的疑问

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and e.mst020_id = a.id) j
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and **e.mst020_id = a.id**) j on j.mst021_id = a.id
但当我处理此查询时,错误显示:

您的SQL语法有错误;在第5行附近,查看与MySQL服务器版本相对应的手册,以了解要使用的正确语法

我正在尝试学习sql,因为在oracle,如果g有这样的子查询,这不是问题。thx

您缺少一个ON语句来处理其余的连接。 我已重新格式化您的查询:

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (
                SELECT e.pict as pict 
                FROM mst021 e 
                WHERE e.line_number = 
                                (
                                        SELECT max(f.line_number) 
                                        FROM mst021 f 
                                        WHERE f.mst020_id = a.id
                                )
                    AND e.mst020_id = a.id
          ) j
如您所见,最后一个左连接没有on子句,最后一个and放错了位置。此外,在最内部的查询中,请选择max,以引用最外部的查询。这是不可能的。您可能应该重写查询,至少,我不知道您想做什么,所以我无法更正它。

您缺少一条ON语句,无法与join的其余部分一起使用。 我已重新格式化您的查询:

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
left join (
                SELECT e.pict as pict 
                FROM mst021 e 
                WHERE e.line_number = 
                                (
                                        SELECT max(f.line_number) 
                                        FROM mst021 f 
                                        WHERE f.mst020_id = a.id
                                )
                    AND e.mst020_id = a.id
          ) j

如您所见,最后一个左连接没有on子句,最后一个and放错了位置。此外,在最内部的查询中,请选择max,以引用最外部的查询。这是不可能的。您可能应该重写查询,至少,我不知道您想做什么,所以我无法更正它。

我有一个答案。这个错误是因为我在子查询和外部子查询处连接表,如下所示

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and e.mst020_id = a.id) j
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and **e.mst020_id = a.id**) j on j.mst021_id = a.id
所以我改成了这样,这是成功的

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number),g.mst021_id from mst021 f )) j on j.mst021_id = a.id

在我的sql中,我们不能与外部子查询中的表联接,我有一个答案。这个错误是因为我在子查询和外部子查询处连接表,如下所示

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and e.mst020_id = a.id) j
select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number) from mst021 f where f.mst020_id = a.id)
     and **e.mst020_id = a.id**) j on j.mst021_id = a.id
所以我改成了这样,这是成功的

select c.*,j.pict
from mst020 a
inner join mst022 c on c.mst020_id = a.id
    left join (select e.pict as pict from mst021 e 
where e.line_number = 
     (select max(f.line_number),g.mst021_id from mst021 f )) j on j.mst021_id = a.id

在我的sql中,我们不能在外部子查询中与表联接

派生表必须有别名:从mst021 e中选择e.pict作为pict,其中e.line_number=从mst021 f中选择maxf.line_number,其中f.mst020_id=a.id作为TMPy左联接后需要使用表HMM我已尝试但仍有错误..派生表必须有别名:选择e.pict作为来自mst021 e的pict,其中e.line_编号=从mst021 f中选择maxf.line_编号,其中f.mst020_id=a.id=作为TMP您需要在离开后使用一个表HMM我已尝试,但仍有错误..请编辑您的问题以显示更正的查询和错误消息请编辑您的问题以显示更正的查询和错误消息