SQL查询卡在Infintite循环中

ful*_*ons 0 sql infinite-loop

我在我的数据库上运行一个非常简单的SQL查询,它似乎一遍又一遍地返回相同的记录,创建一个无限循环.也许我错过了一些明显的东西,但我没有看到它.这是查询:

select s.customer as 'Customer',
    s.store as 'Store',
    s.item as 'Item',
    d.dlvry_dt as 'Delivery',
    i.item_description as 'Description',
    mj.major_class_description as 'Major Description',
    s.last_physical_inventory_dt as 'Last Physical Date',
    s.qty_physical as 'Physical Qty',
    s.avg_unit_cost as 'Unit Cost',
    [qty_physical] * [avg_unit_cost] as Value
from database.DELIVERY d,
    database.STORE_INVENTORY s,
    database.ITEM_MASTER i,
    database.MINOR_ITEM_CLASS mi,
    database.MAJOR_ITEM_CLASS mj,
    database.STORE_INVENTORY_ADJUSTMENT sa
where sa.store = s.store
    and s.last_physical_inventory_dt between '6/29/2011' and '7/2/2011'
    and s.customer = '20001'
    and s.last_physical_inventory_dt is not null
Run Code Online (Sandbox Code Playgroud)

有一条记录落在2011年7月1日,它会一直重复,直到我取消查询.

有什么帮助防止这种情况?

Ger*_*rat 6

你即将加入所有这些表:database.DELIVERY,database.ITEM_MASTER,database.MINOR_ITEM_CLASS,和database.MAJOR_ITEM_CLASS-由于没有指定如何加入他们的行列.您需要指定这些表与其余表的连接方式.

如果这些表中的每一个只有100行,它将为您提供100*100*100*100行(1亿)最小行!(见笛卡尔加入)

  • 笛卡尔积^ 5 (2认同)