使用连接更新列
SELECT lott.id as lottery_id,lott.abbr,lott.currency,payments.id as payment_id,
payment_prizes.prize_id,prizes.name,prizes.currency as prizes_currency
FROM lotteries lott
JOIN lottery_payments payments
ON
payments.lottery_id = lott.id
JOIN lottery_payment_prizes payment_prizes
ON
payment_prizes.payment_id = payments.id
JOIN lottery_prizes prizes
ON
prizes.id = payment_prizes.prize_id
WHERE lott.currency = "ID"
我需要更新 lottery_prizes 表中的所有货币,其中 id 来自上面的查询。 我这样做时
UPDATE lottery_prizes SET currnecy = 'ID'
WHERE id IN(SELECT prizes.id
FROM lotteries lott
JOIN lottery_payments payments
ON
payments.lottery_id = lott.id
JOIN lottery_payment_prizes payment_prizes
ON
payment_prizes.payment_id = payments.id
JOIN lottery_prizes prizes
ON
prizes.id = payment_prizes.prize_id
WHERE lott.currency = "ID")
出现以下错误:
/* SQL 错误 (1093): 您无法在 FROM 子句中指定用于更新的目标表 'lottery_prizes' */ 谢谢大家
SELECT lott.id as lottery_id,lott.abbr,lott.currency,payments.id as payment_id,
payment_prizes.prize_id,prizes.name,prizes.currency as prizes_currency
FROM lotteries lott
JOIN lottery_payments payments
ON
payments.lottery_id = lott.id
JOIN lottery_payment_prizes payment_prizes
ON
payment_prizes.payment_id = payments.id
JOIN lottery_prizes prizes
ON
prizes.id = payment_prizes.prize_id
WHERE lott.currency = "ID"
I need to UPDATE all currency from lottery_prizes table WHERE id's are from query above.
I did this
UPDATE lottery_prizes SET currnecy = 'ID'
WHERE id IN(SELECT prizes.id
FROM lotteries lott
JOIN lottery_payments payments
ON
payments.lottery_id = lott.id
JOIN lottery_payment_prizes payment_prizes
ON
payment_prizes.payment_id = payments.id
JOIN lottery_prizes prizes
ON
prizes.id = payment_prizes.prize_id
WHERE lott.currency = "ID")
I have this error:
/* SQL Error (1093): You can't specify target table 'lottery_prizes' for update in FROM clause */
Thanks all
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)