您好我想要将名为'灯具'的表格中的值从fixtures.toggle=hidden
更新为fixtures.toggle=visible
。
它应该只更新fixtures.compid
是以下competition.id
之一的灯具
在一个名为“竞争”的单独表格中。
SELECT *
FROM `competitions`
WHERE `Year` LIKE CONVERT( _utf8 '2012' USING latin1 ) COLLATE latin1_swedish_ci
AND ( `countyid` =4 OR `countyid` =11 OR `countyid` =20 OR `countyid` =22 )
我对SQL很陌生,并希望在正确的方向上找到一点。
答案 0 :(得分:1)
因此,如果我理解,您希望更新上述查询返回的fixtures.compid
中包含competitions.id
的行。使用IN ()
子查询返回competitions.id
:
UPDATE
fixtures
SET toggle = 'visible'
WHERE
/* Modify rows currently hidden (not strictly necessary since they would all end up with the same value anyway) */
toggle = 'hidden'
/* Retrieve competitions.id matching your criteria */
AND compid IN (
SELECT id
FROM `competitions`
WHERE `Year` LIKE CONVERT( _utf8 '2012' USING latin1 ) COLLATE latin1_swedish_ci
/* IN () clause is equivalent to your chain of OR operations */
AND countyid IN (4, 11, 20, 22)
)