select a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
from 
tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                 left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                 left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
where b.UserType=1 and a.Hidden=0select top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                      left join tb_City d on a.CityID=d.id 
                      left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
where a.Hidden=0 order by LastTime desc这是两个Sql语句,要把这俩读出的内容一起显示出来,并且不能重复,这个怎么俩个写成一个啊

解决方案 »

  1.   

    select a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
    from 
    tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                    left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                    left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where b.UserType=1 and a.Hidden=0 
    union all------------------
    select top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
    from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                          left join tb_City d on a.CityID=d.id 
                          left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where a.Hidden=0 order by LastTime desc 
      

  2.   


    select a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
    from 
    tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                    left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                    left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where b.UserType=1 and a.Hidden=0 union allselect top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
    from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                          left join tb_City d on a.CityID=d.id 
                          left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where a.Hidden=0 order by LastTime desc 
      

  3.   

    ---不能重复直接用unionselect a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
    from 
    tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                    left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                    left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where b.UserType=1 and a.Hidden=0 
    union
    select top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
    from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                          left join tb_City d on a.CityID=d.id 
                          left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where a.Hidden=0 order by LastTime desc 
      

  4.   


    union all 包含重复数据的  应该用union
      

  5.   

    用union是不重复的 union all有重复数据
      

  6.   

    服务器: 消息 104,级别 15,状态 1,行 1如果语句中包含 UNION 运算符,那么 ORDER BY 子句中的项就必须出现在选择列表中。
      

  7.   


    select a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
    from 
    tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                    left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                    left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where b.UserType=1 and a.Hidden=0 unionselect top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
    from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                          left join tb_City d on a.CityID=d.id 
                          left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where a.Hidden=0 order by LastTime desc 
      

  8.   

    select * from 
    (select a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,b.LastTime 
    from 
    tb_Lawyer_User a right join tb_OnLine_User b on a.UserID=b.UserID 
                    left join tb_Pro c on a.ProID=c.id join tb_City d on a.CityID=d.id 
                    left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where b.UserType=1 and a.Hidden=0 unionselect top 10 a.ID,a.FullName,a.SmallNamePath,c.name as ProName,d.Name as CityName,e.Domain,a.LastTime 
    from tb_Lawyer_User a left join tb_Pro c on a.ProID=c.id 
                          left join tb_City d on a.CityID=d.id 
                          left join tb_Domain e on (a.UserID=e.UserID and e.UserType=1) 
    where a.Hidden=0)t order by LastTime desc 
      

  9.   

    order by a.LastTime desc