select * from ( select Id id ,L_title tit,L_con con,L_date date,L_author aut from lab 
                    union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
union select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien 
union select Id id ,R_title tit,R_con con,R_date date,R_author aut from research
union select Id id ,Title tit,Content con,Date date,Author aut from news
union select Id id ,W_title tit,W_con con,W_date date,W_author aut from windows) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc 这个语句在MYSQL中可以查询,  但是放到java中 就不行了, 最多最能写两句,如下:
 select * from ( select Id id ,L_title tit,L_con con,L_date date,L_author aut from lab 
                    union select Id id ,I_title tit,I_con con,I_date date,I_author aut from introduction
) a where a.tit='作者' or a.con='作者' or a.aut='作者' order by date desc 
否则将报错:
[ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO net.fckeditor.connector.Dispatcher - Connector initialized to net.fckeditor.connector.impl.ContextConnector
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 Id id ,M_title tit,M_con con,M_date date,M_author aut from mien union sel' at line 1

解决方案 »

  1.   

    这不是放到MYSQL还是放到java的问题啊,他们最终都是要到mysql的数据库引擎执行的。
    怀疑你在java拼接字符串的时候哪里出错了,把java执行的sql打印出来看看吧。
    另外,如果你的这些表里没有重复记录,用union all吧,效率更高。
      

  2.   

    应该是你java拼装字符串的时候出了问题
      

  3.   

    不止支持两个表吧   应该是java拼装sql时,出的问题,打印一下吧
      

  4.   

    应该 也没问题呀,   我任意删除几条  剩下一个union的时候 它就正常了哦,,
      

  5.   

    check the manual that corresponds to your MySQL server version for the right syntax to use near 'select Id id ,M_title tit,M_con con,M_date date,M_author aut from mien union sel' at line 1
    错误提示在第三个union附近,你删了后面的肯定可能就是把错误部分删掉了
      

  6.   

    问题 解决了  但是我问题根源还不是很确定,  我把两行之间 用的" 连接符 与 SQL语句结尾部分空开一点 貌似就没问题了