這裏是我的查詢:如何在UPDATE語句中使用JOIN?
UPDATE reputations SET
type = new.type,
score = new.score,
qora = NOT (new.post_id = (SELECT t1.id
FROM qanda t1
WHERE (EXISTS (SELECT 1
FROM qanda t2
WHERE ID = new.post_id
AND t1.ID = t2.related)
OR t1.id = new.post_id)
AND Type = 0)),
question_id = (SELECT t1.id
FROM qanda t1
WHERE (EXISTS (SELECT 1
FROM qanda t2
WHERE ID = new.post_id
AND t1.ID = t2.related)
OR t1.id = new.post_id)
AND Type = 0),
post_id = new.post_id,
table_code = new.table_code,
comment_id = new.comment_id,
owner_id = new.author_id,
date_time = UNIX_TIMESTAMP()
WHERE events_table_id = old.id;
所有我想要做的是去除那些子查詢的一個,因爲兩者是相同的。我怎樣才能做到這一點?
我不認爲你的括號平衡。 –
@GordonLinoff真的......我又增加了一個。 –