简体   繁体   English

我想将第一个SQL表中的数据插入第二个SQL表中,而第二个表中不存在额外的列

[英]I want to insert data from first SQL table into second one also with an extra column not present in the second one

So currently I am using this query 所以目前我正在使用此查询

INSERT INTO tb_first_wallet_transactions 
(
    vendor_id, 
    amount, 
    transaction_type, 
    status, 
    checksumhash
)
SELECT 
    vendor_id, 
    amount, 
    transaction_type, 
    status, 
    checksumhash 
FROM 
    tb_second_wallet_transactions 
WHERE id = 1

There is also a column name type in tb_first_wallet_transaction that can be 0 or 1 , that I also needs to add, but the problem is that there is no such column in the second table. tb_first_wallet_transaction中还有一个列名type ,可以是01 ,我也需要添加,但是问题是第二个表中没有这样的列。

One solution is that I run a query which changes does type == 1 after a certain time stamp (ie of the insertion time of above query) 一种解决方案是我运行一个查询,该查询在一定的时间戳(即上述查询的插入时间)之后更改类型== 1

But I want to do all the insertion in one single query. 但是我想在一个查询中完成所有插入操作。 Is that possible ?? 那可能吗 ??

Just add the type in the column list and add a default value in your SELECT : 只需在列列表中添加type ,然后在SELECT添加默认值即可:

INSERT INTO tb_first_wallet_transactions (vendor_id, amount, transaction_type, status, checksumhash, type)
    SELECT
        vendor_id,
        amount,
        transaction_type,
        status,
        checksumhash,
        0 -- Choose your default value
    FROM tb_second_wallet_transactions
    WHERE
        id = 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果第一个表中不存在,我想从第二个表中获取数据 - I want fetch data from second table if not present in first table 我想使用 MySQL 中第二个查询中第一个查询的列将两个查询合二为一 - I want to use two queries into one using a column from first query in the second one in MySQL 当第一个表中的列值与第二个表中的列值匹配时,显示一个表中的数据 - Display data from one table when a column value in first table matches column value in second table 将表链接到第二个表并将数据从第一个表多次拉到第二个表 - Linking a table to a second table and pulling data from the first one to the second one multiple times SQL连接,从第二个表中提取值并将其添加到第一个表中 - Sql join, extract value from the second table and add it to the first one MYSQL:如何将整行从一个表复制到 mysql 中的另一个表,第二个表有一个额外的列? - MYSQL: How to copy an entire row from one table to another in mysql with the second table having one extra column? 将第二个 MySQL 表中的数据添加到第一个表的结果中 - Add data from second MySQL table to the result from the first one 从第一个表中选择数据并将其与第二个表进行比较 - Select data from first table and compare it with second one 我如何总是从一个表中提取数据,又如何从第二个表中提取数据(如果MySQL中存在的话)? - How do I always pull data from one table, but also pull data from a second table if it's there in MySQL? 每秒将数据插入MySQL表(每秒一次) - Insert data to MySQL table every second (one time per second)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM