A
A
alst1612015-12-14 02:47:01
MySQL
alst161, 2015-12-14 02:47:01

SQL: change duplicates. how to do?

Is it possible to implement the following without resorting to php. there is a url table, the keyword field contains the product alias, some may be the same, how to make a request to change the alias for duplicates, for example, add a random number

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey S., 2015-12-14
@Winsik

SET @r=0;
select id,tname,CONCAT (taliase , addid) as aliase from 
(
   select * from (
            SELECT  id,tname,taliase,@r:[email protected]+1 as addid
            FROM FF as f1
            GROUP BY f1.tname,f1.taliase
            UNION 
            SELECT  id,tname,taliase,"" as addid FROM FF as f2
            GROUP BY f2.taliase
            ORDER BY taliase DESC
            ) as t1
   order by t1.id,t1.addid
   
) as t2
group by t2.id

the sign was like this:
CREATE TABLE FF
  (`id` int, `tname` varchar(20), `taliase` varchar(20))
;
  
INSERT INTO FF
  (`id`, `tname`, `taliase`)
VALUES
  (1, 'baranka', 'hleb'),
  (2, 'bulka', 'hleb'),
  (3, 'pirozhok', 'hleb'),
    (4, 'konfeta','sladkoe'),
    (5, 'karamel','sladkoe')
;

N
nozzy, 2015-12-14
@nozzy

update table as t1
inner join 
(
  select 
  keyword,
  count(*) as cnt
  from table
  group by keyword
) t2 on t2.keyword = t1.keyword
set t1.keyword = concat(t1.keyword, floor(rand() * 10000000)) 
where t2.cnt > 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question