0

使用 QT5.15.1,Windows 10 64,最后 Mysql 连接:

我的查询:

SELECT ata, description, min(duedate) as duedate, tbocalendar, tbocalendar2, table_name FROM (SELECT ata, description, duedate1 AS duedate, tbocalendar, tbocalendar2, 'part_log' as table_name FROM part_log WHERE tbocalendar!= 'N/A' AND removed = 'FALSE' AND activecheck = 'ACTIVE' AND immatriculation=? UNION SELECT ata, description, duedate2 AS duedate, tbocalendar, tbocalendar2, 'part_log' as table_name FROM part_log WHERE removed = 'FALSE' AND activecheck = 'ACTIVE' AND immatriculation=? UNION SELECT ata, element as description, echeance AS duedate,  tbocalendar, 'N/A' as tbocalendar2, 'ltr_log' as table_name  FROM ltr_log  WHERE date_cloture = 'N/A' AND echeance !='N/A' AND immatriculation=?) WHERE substr(description,1,5)!='Carte' LIMIT 1

这会返回一个我不明白的错误:

#1064 - Erreur de syntaxe près de 'LIMIT 0, 25' à la ligne 1

为什么我所有使用如下子查询的查询都返回此错误?:

Select xxx,yyyy from (Select xxx,yyyy from table_name union all Select xxx,yyyy from table_name1)

我需要有一个像这样的查询: Select MIN(date_example) FROM (SELECT date1 as date_example from table1 UNION ALL SELECT date2 as date_example from table2)

所有这些查询都可以在 sqlite 上正常工作,但是它们不能在 mysql 上工作,并且没有任何解释的错误对我没有帮助......

非常感谢你们的帮助;-)

4

1 回答 1

0

您应该为您构建的新表定义一个别名:

Select 
   MIN(tableAlias.date_example) 
FROM 
   (
   SELECT 
      date1 as date_example 
   from table1 
   UNION ALL 
   SELECT date2 as date_example from table2
   ) As tableAlias
于 2021-12-06T20:24:37.833 回答