-1

我正在使用 Sqlite-net-pcl。我需要哪个查询更好用。如果至少有一条记录,我正在表中搜索。

第一次查询

Select exists(Select 1 from invnentory where itemname='box2')

第二次查询

Select count(*) from inventory where itemname='box2'

两个查询都正常工作。但是,使用 sqlite-net-pcl 的最佳方法是什么?

4

1 回答 1

0

这个查询:

Select count(*) from inventory where itemname = 'box2'

通常必须进行全表扫描以返回满足WHERE子句中条件的行数。

但是这个:

Select exists(Select 1 from invnentory where itemname='box2')

一旦找到满足条件的第一行,它将立即返回,并且只有在没有这样的行时才会进行全表扫描。

所以EXISTS应该表现更好。

于 2020-08-26T12:29:53.547 回答