2012-03-03 48 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

相關問題