如何在Mysql中仅将不同的值从一个表复制到另一个表? [英] how to copy only distinct values from one table to another in Mysql?

查看:43
本文介绍了如何在Mysql中仅将不同的值从一个表复制到另一个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大约 2.5GB 的 MySql 数据库,

I have a MySql database round-about 2.5GB,

表[A]有以下列,|anoid||查询||日期||物品等级||url|

我刚刚创建了另一个表[b],其中只有 |query||date|

I have just created another table[b] having columns only |query| and |date|

我想在查询列中插入所有不同的记录,它们各自的日期,从表[A]到[B],有什么快速查询吗?

I want to insert all the distinct records in query column, with it's respective date, from Table[A] to [B], is there any fast query?

推荐答案

使用 INSERT INTO ... SELECT:

INSERT INTO Tableb(query, date)
SELECT query, MAX(Date) AS MAXDate
FROM Tablea
GROUP BY query

这将为您提供具有最新 date 的独特 query.

This will give you distinct query with the most recent date.

这篇关于如何在Mysql中仅将不同的值从一个表复制到另一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆