mysql 获得最新的数据并且去除重复

商品表 product

字段 id、 product_code、product_name、create_date

select * from (select *,product_code as code from product order by create_date desc) t group by code;

只限于mysql数据库

时间: 2024-08-27 03:45:42

mysql 获得最新的数据并且去除重复的相关文章

mysql 去除重复数据 语句

纠结的过程: mysql> select * from role group by role_name,deleted; +---------+-----------+---------+ | role_id | role_name | deleted | +---------+-----------+---------+ | 2 | xue | 12 | | 1 | zhao | 12 | | 3 | zhao | 13 | +---------+-----------+---------+

mysql数据去除重复及相关优化(转)

由于mysql不支持同时对一张表进行操作,即子查询和要进行的操作不能是同一张表,因此需要通过临时表中专以下. 1.单字段重复 生成临时表,其中uid是需要去重的字段 create table tmp_uid as (select uid from user_info group by uid having count(uid)) create table tmp_id as (select min(id) from user_info group by uid having count()uid

mysql 去除重复 Select中DISTINCT关键字的用法

在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用它来返回不重复记录的条数,而不是用它来返回不重记录的所有值.其原因是 distinct只能返回它的目标字段,而无法返回其它字段,这个问题让我困扰了很久,用distinct不能解决的话,我只有用二重循环查询来解决,而 这样对于一个数据量非常大的站来说,无疑是会直接影响到效率的.所以我花了很多时间来研究这个问题,网上也查不到解决方案,期间把容容拉来帮忙,

按天去除重复数据,为0则取0,否则取最大的那个值

测试数据: mysql> select * from t2; +----+--------+---------------------+------------+ | id | userid | inputDate | infoStatus | +----+--------+---------------------+------------+ | 1 | 1 | 2014-07-11 00:00:00 | 20013 | | 2 | 1 | 2014-07-11 00:00:00 | 0 |

JAVA数组去除重复数据

一.用List集合实现   int[] str = {5, 6, 6, 6, 8, 8, 7,4}; List<Integer> list = new ArrayList<Integer>(); for (int i=0; i<str.length; i++) { if(!list.contains(str[i])) { list.add(str[i]); } } System.out.println("去除重复后的list集合"+list); 输出结果是

去除重复的数据

在工作工程中我们不必要会遇到,在数组中有重复数据的时候,如何去除重复的数据呢? 第一种:利用NSDictionary的AllKeys(AllValues)方法 代码: NSArray *dataArray = @[@"2014-04-01",@"2014-04-02",@"2014-04-03", @"2014-04-01",@"2014-04-02",@"2014-04-03", @&

List集合去除重复数据

[转自]Java中List集合去除重复数据的方法 1. 循环list中的所有元素然后删除重复 public static List removeDuplicate(List list) { for ( int i = 0 ; i < list.size() - 1 ; i ++ ) { for ( int j = list.size() - 1 ; j > i; j -- ) { if (list.get(j).equals(list.get(i))) { list.remove(j); }

Java实现数组去除重复数据的方法详解

一.用List集合实现 int[] str = {5, 6, 6, 6, 8, 8, 7,4}; List<Integer> list = new ArrayList<Integer>(); for (int i=0; i<str.length; i++) { if(!list.contains(str[i])) { list.add(str[i]); } } System.out.println("去除重复后的list集合"+list); 输出结果是:

MySQL 创建唯一索引忽略对已经重复数据的检查

MySQL 创建唯一索引忽略对已经重复数据的检查 在创建唯一索引的基础上加上关键字"IGNORE "即可. # 重复数据 mysql> select aid,count(aid) as total ,email,tel_no,account_type,exten,passwd from fudao_admin group by user_name having total> 1; +-------+-------+--------------------------+---