选择查询给出不同的结果

时间:2011-01-10 10:09:47

标签: sql-server select

我已经编写了select fallowing查询,但是它在查询中出错地给出了不同的结果。请告诉我。查询:

Select count(*) Count from conflux.dbo.SABR_Master M 
        Where M.Email in (
        select top 26 Email from conflux.dbo.SABR_Master L 
        where (L.titleid In (Select titleid From sabr_titlemasters Where IsDisplay=1 And  title like '%Account Executive%' OR title like '%Account Manager%' OR title like '%Accounts Manager%' OR title like '%admin%'  ))
        ) and M.Email NOT IN (select Email from [sample client].dbo.Comm_CompanyData)

1 个答案:

答案 0 :(得分:1)

试试这个

Select  count(*) Count 
from    conflux.dbo.SABR_Master M 
Where   M.Email in (select  top 26 
                            L.Email 
                    from conflux.dbo.SABR_Master L 
                    where (L.titleid In (   Select  titleid 
                                            From    sabr_titlemasters 
                                            Where   IsDisplay=1 And  
                                                    (title like '%Account Executive%' OR 
                                                    title like '%Account Manager%' OR 
                                                    title like '%Accounts Manager%' OR 
                                                    title like '%admin%')))
                    ORDER BY L.Email) and 
        M.Email NOT IN (select  Email 
                        from [sample client].dbo.Comm_CompanyData)

我在您的标题附近添加了括号,如 OR和订单依据,以保持您的26封电子邮件相同。如果没有指定order by,数据库可以按随机顺序返回它们,这可以给你不同的结果。