2012-03-03 27 views
1

您好我想更新名为'夹具'从fixtures.toggle=hiddenfixtures.toggle=visible表中的值。
它应该只更新其中fixtures.compid是以下其中一个competition.id 在称为“竞争”的单独表中。更新table1其中table2值多个变量

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,并会赞赏在正确的方向点。

回答

1

因此,如果我理解,您正在寻找更新competitions.id之间的fixtures.compid行,上面的查询返回。这可能是最容易使用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) 
) 
+0

完美,谢谢。与我想象的相似,我无法在脑海中获得正确的顺序。 – user1247030 2012-03-03 17:32:32

+0

不客气,欢迎来到Stack Overflow。 – 2012-03-03 18:37:58

相关问题