I’m running a pretty simple SQL query on my database, and it seems to be returning the same record over and over, creating an infinite loop. Maybe I’m missing something obvious, but I don’t see it. Here’s the query:
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
There is one record that falls on 7/1/2011 and it repeats it forever until I cancel the query.
Any help on preventing this?
You’re joining all these tables:
database.DELIVERY,database.ITEM_MASTER,database.MINOR_ITEM_CLASS, anddatabase.MAJOR_ITEM_CLASS– without specifying how to join them. You need to specify how these tables are joined with the rest.If each of these tables has ONLY 100 rows, it will give you 100 * 100 * 100 * 100 rows (100 million) minimum rows! (see Cartesian Join)