我正在使用SELECT子句中的子查询对mysql进行查询,我收到此错误:#2014 - 命令不同步;你现在不能运行这个命令 我无法解决它。你能帮帮我吗?
SELECT e.IdDocumento, e.CveDistrito, d.STCT_NOM, e.CveJuzgado, j.CTJU_DESCR, e.NumDocumento, e.IdRamoDocumento, r.Descripcion....., (SELECT pd.nombre FROM ParteDocumento AS pd WHERE pd.IdDocumento = e.IdDocumento) AS NombreActor
FROM Documentos AS e
INNER JOIN CtRamo AS r ON ( r.IdRamo = e.IdRamoDocumento )
INNER JOIN CtEstado AS edo ON ( edo.CveEstado = e.CveEstado )
INNER JOIN CTDISJUD AS d ON (d.STCT_NUM = e.CveDistrito)
INNER JOIN CTJUZGAD AS j ON (j.CTJU_MUNIC = e.CveDistrito AND j.CTJU_JUZGA = e.CveJuzgado)
LEFT JOIN CtMedioPresentacion AS m ON ( m.IdMedioPresentacion = e.IdMedioPresentacion )
WHERE e.IdTipoDocumento =1 AND e.EsRecibido =1
这是我的查询。我在SQL Server中执行了相同的查询,但它确实有效!
答案 0 :(得分:0)
我不是百分百肯定,但我认为你不能在from
内的子选项中使用select
子句中的表格。但为什么不简单地加入表而不是subselect:
SELECT e.IdDocumento, e.CveDistrito, d.STCT_NOM, e.CveJuzgado, j.CTJU_DESCR, e.NumDocumento, e.IdRamoDocumento, r.Descripcion....., pd.nombreNombreActor
FROM Documentos AS e
INNER JOIN CtRamo AS r ON ( r.IdRamo = e.IdRamoDocumento )
INNER JOIN CtEstado AS edo ON ( edo.CveEstado = e.CveEstado )
INNER JOIN CTDISJUD AS d ON (d.STCT_NUM = e.CveDistrito)
INNER JOIN CTJUZGAD AS j ON (j.CTJU_MUNIC = e.CveDistrito AND j.CTJU_JUZGA = e.CveJuzgado)
LEFT JOIN CtMedioPresentacion AS m ON ( m.IdMedioPresentacion = e.IdMedioPresentacion )
LEFT JOIN ParteDocumento as pd on pd.IdDocumento = e.IdDocumento
WHERE e.IdTipoDocumento =1 AND e.EsRecibido =1