以下查询让我感到困惑。如果我products
并WHERE (inventory_to_pos.POSID IS NULL OR inventory_to_pos.POSID = ?)
绑定POSID
可能存在或不存在inventory_to_pos
,那么不会显示LEFT JOIN
表格中的所有行。当IS NULL
表格时,我不应该从原始表格中获取所有行,当我只对原始表格进行过滤并在LEFT JOIN
上使用SELECT products.ID,products.NAME,products.VOLUME,productcombinations.PRODUCTID,productcombinations.PART,inventory_to_pos.FULLCOUNT
FROM products
LEFT JOIN productcombinations ON products.ID = productcombinations.PARTOF
LEFT JOIN inventory_to_pos ON products.ID = inventory_to_pos.PRODUCT
WHERE products.INVENTORY = 1
AND products.AVAILABLE = 1
AND products.ID > 0
AND (inventory_to_pos.POSID IS NULL OR inventory_to_pos.POSID = ?);
时inventory_to_pos.PRODUCT
1}}'ed tables?
inventory_to_pos.POSID
如果给定产品和POSID不存在- (void) calculateSize {
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Event"];
NSArray *data = [self.managedObjectContext executeFetchRequest:request error:nil];
NSLog(@"Size of %@: %zd", NSStringFromClass([data class]), malloc_size((__bridge const void *) data));
int totalSize = 0;
for(NSManagedObject *object in data)
{
totalSize += malloc_size((__bridge const void *) object);
}
NSLog(@"Managed Object Size total:%d", totalSize);
}
和wp-config.php
,则不会给出任何行。为什么呢?
答案 0 :(得分:1)
将所有相关的invetory_to_pos
子句移至LEFT JOIN,即:
SELECT
products.ID,
products. NAME,
products.VOLUME,
productcombinations.PRODUCTID,
productcombinations.PART,
inventory_to_pos.FULLCOUNT
FROM
products
LEFT JOIN productcombinations ON products.ID = productcombinations.PARTOF
LEFT JOIN inventory_to_pos ON products.ID = inventory_to_pos.PRODUCT AND (
inventory_to_pos.POSID IS NULL
OR inventory_to_pos.POSID = ?
)
WHERE
products.INVENTORY = 1
AND products.AVAILABLE = 1
AND products.ID > 0