本文介绍了更好的sp来获得无与伦比的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



有两个表tblProperty和tblSales

tblProperty在特定字段中包含此值

机械

家具

单位

土地



i在销售中创建页面并在销售中使用属性弹出窗口,因此属性值保存到tblsles作为tblProperty表主键值。

tblSales包含

机器

家具



现在我想得到只有平坦和土地,这在tblSales中不存在



任何人都可以帮我怎么做?



谢谢。

hi
am having two tables tblProperty and tblSales
tblProperty contains this values in perticular field
Machinery
Furniture
Flat
Land

i created page in sales and am using property popup in sales so property value saving to tblsles as tblProperty tables primary key value.
tblSales contains
machinery
Furniture

now i want to get only Flat and Land which is not exist in tblSales

can any one help me how to do this?

Thank you.

推荐答案

SELECT COL_NAME FROM TABEL1 A, TABLE2 B
WHERE A.ID <> B.ID



我不确定这是否正确,我认为这满足了你的问题......


i''m not sure this is correct , i think this is satisfied your question...


SELECT Flat, Land FROM tblProperty
WHERE Furniture NOT IN 
(SELECT Furniture FROM tblProperty p
INNER JOIN tblSales s ON p.Furniture = s.Furniture AND p.Machinery = s.Machinery)





方法2:在查询中使用NOT IN子句。



Method 2: Simply using NOT IN clause in the query.

SELECT Flat, Land FROM tblProperty
WHERE Machinery NOT IN (SELECT Machinery FROM tblSales)
AND Furniture NOT IN (SELECT Furniture FROM tblSales)





我认为如果您的表包含大量记录,方法2会更慢。那是因为tblSales表在这里被查询了两次。所以第二次查询涉及的整体数据很高。

我建议你仍然检查两个查询的查询计划,并选择最好的计划。



希望这有帮助!



I think Method 2 will be slower if your tables contain huge records. That''s because tblSales table is queried two times here. So the overall data involved in second query is high.
I would suggest you still check the query plan for both the queries and go with the best plan.

Hope this helps!


这篇关于更好的sp来获得无与伦比的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 13:06