我有这个更新查询,当我的地方有2个条件但是当我添加3个以上时它无效。谁能看到它并告诉我什么是错的。谢谢。
继承我的疑问:
$sSQLupdate = "UPDATE settings, holidaytype SET
settings.companyName = '$companyname',
settings.companyAddress = '$companyaddress',
settings.companyContact = '$companycontact',
settings.excessot1 = '$excessot1',
settings.multiplierOT1 = '$multiplier1',
settings.excessot2 = '$excessot2',
settings.multiplierOT2 = '$multiplier2',
settings.ndRangeFrom = '$ND_in',
settings.ndRangeTo = '$ND_out',
settings.multiplierNd = '$NDmul',
holidaytype.multiplier = '$regularmul', *(mustbe in holidaytype.id = '1')
holidaytype.multiplier = '$specialmul', *(mustbe in holidaytype.id = '2')
holidaytype.multiplier = '$doubleregmulmul', *(mustbe in holidaytype.id = '3')
holidaytype.multiplier = '$doublespecmul' *(mustbe in holidaytype.id = '4')
WHERE settings.id = 1 AND holidaytype.id = '1' AND holidaytype.id = '2' AND holidaytype.id = '3' AND holidaytype.id = '4'";
答案 0 :(得分:2)
试试这个:
WHERE settings.id = 1 AND holidaytype.id IN ('1','2','3','4')
要根据holidaytype.multiplier
更新holidaytype.id
条件,建议您使用CASE
语句或单独查询。
答案 1 :(得分:1)
因为所有这三个条件都不可能是真实的,即
WHERE settings.id = 1 AND holidaytype.id = '1' AND holidaytype.id = '2' AND holidaytype.id = '3' AND holidaytype.id = '4'";
如果holidaytype.id = '1'
则不能'2' or '3' or '4'
您最好使用 IN
WHERE settings.id = 1 AND holidaytype.id IN ('1','2','3','4')
答案 2 :(得分:1)
您需要使用OR
代替AND
AND
,因为它们无法同时为真,其中一个必须为真。试试这个:
WHERE settings.id = 1
AND (holidaytype.id = '1' OR holidaytype.id ='2' OR holidaytype.id ='3' OR holidaytype.id ='4')";
或与IN
子句一起使用:
WHERE settings.id = 1 AND holidaytype.id IN ('1','2','3','4')";
您的更新没有任何意义,请更新两个具有彼此条件的表格。要么单独更新每个表,要么使用连接表。
答案 3 :(得分:0)
使用括号分隔布尔语句:
WHERE settings.id = 1 AND (holidaytype.id = '1' OR holidaytype.id = '2' OR holidaytype.id = '3' OR holidaytype.id = '4');