想要避免笛卡尔积仍然得到2行而不是只有1行 [英] Want to avoid cartesian product still getting 2 rows instead of only ONE
本文介绍了想要避免笛卡尔积仍然得到2行而不是只有1行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究Sql servar 2005;这是查询
I am working on Sql servar 2005; here is the query
SELECT distinct DailyAttendence.Empid,DailyAttendence.LeaveType,DailyAttendence.today as 'Half day taken at', EmployeeOnFulldayleave.LeaveDay FROM DailyAttendence
CROSS JOIN EmployeeMaster CROSS JOIN EmployeeOnFulldayleave
where DailyAttendence.LeaveType='h' and EmployeeOnFulldayleave.fleave =1 and DailyAttendence.Empid=2
它仍然显示两条记录!它应该只有一个记录!
2 H 06-08-2013 06-08-2013
it is still showing two records! it should only be one record!
2 H 06-08-2013 06-08-2013
2 H 06-08-2013 06-09-2013
PLZ帮我吧!
感谢提前
Priya Tiwari
2 H 06-08-2013 06-09-2013
plz help me its urgent!
Thankx in advance
Priya Tiwari
推荐答案
它们是截然不同的 - 所以它正在做它应该做的事情。您的查询返回两条符合条件的记录 - 因此您需要优化条件,或者使用TOP限制返回的记录数:
They are distinct and different - so it is doing exactly what it should. Your query returns two records which match your criteria - so either you need to refine your criteria, or limit the number of record you return with TOP:
SELECT DISTINCT TOP 1 ...
这篇关于想要避免笛卡尔积仍然得到2行而不是只有1行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文