2012-01-11 72 views
0

我想[更新]从交易表TRANSACTION_ID到CMAS表,但我失去了一些东西......不知道从哪里引用CMAS表,所以它不会出错#1054 - Unknown column 'cmas.property_id' in 'where clause'MySQL的桌到桌SQL

INSERT INTO `cmas` (`transaction_id`) 
SELECT `transaction_id` 
FROM `transactions` WHERE transactions.property_id = cmas.property_id // this bit is wrong! 

回答

2

既然你提到的评论的更新,这可能是你在找什么:

UPDATE cmas, transactions 
SET cmas.transaction_id = transactions.transaction_id 
WHERE transactions.property_id = cmas.property_id 
+0

这样做!谢谢。 – Robert 2012-01-11 01:45:46

1

你应该把它改写这样的:

INSERT INTO `cmas` (`transaction_id`) 
SELECT `transaction_id` 
FROM `transactions` WHERE transactions.property_id IN (select property_id from `cmas`) 

问题是存在于左部没有选择,所以表达“transactions.property_id = cmas.property_id”是meaninless,因为没有CMAS选择完成。

+0

这个运行,但犯规更新CMAS TRANSACTION_ID – Robert 2012-01-11 01:25:47

1
INSERT INTO cmas (transaction_id) 
SELECT transaction_id 
FROM transactions,cmas 
WHERE transactions.property_id = cmas.property_id 
+0

此运行(当我修改SELECT来'交易.transaction_id')但不更新cmas transaction_id – Robert 2012-01-11 01:25:14

+0

,因为这是比我的更好的解决方案,我会在这里评论: – kenota 2012-01-11 01:27:25

+0

它呢,它返回transaction_id – Robert 2012-01-11 01:33:12