按相应的位置和类型补上''和0union是纵向产生记录,与left join根本是两回事

解决方案 »

  1.   

    SELECT select1,select3 FROM table1 WHERE where1 
    UNION 
    SELECT select2 FROM table2 WHERE where2
    order by select3.id desc
    limit limit1
    提示我unknow table "select3"
    还有就是limit子句是不是这样用也不行啊?
      

  2.   

    当然了UNION 要保证字段数量绝对相等
    类型要兼容
      

  3.   

    若select3为字符型则
    SELECT select1,select3 FROM table1 WHERE where1 
    UNION 
    SELECT select2,'' FROM table2 WHERE where2若select3为数值型则
    SELECT select1,select3 FROM table1 WHERE where1 
    UNION 
    SELECT select2,0 FROM table2 WHERE where2每一个select子句都可以有limit
    但请注意:最后一个limit将对全部查询结果起作用
      

  4.   

    还有个问题!
    SELECT  select11,select12,select13,select14  
    FROM  table1  WHERE  where1    
    UNION    
    SELECT  select21,0,'',0,''
    //select11,select13为数值型则 select12,select14为字符型则   
    FROM  table2  WHERE  where2 
    在网页select12,select13,select14字段显示出来后要么没有,要么只有一部分!是为什么啊?