Fadak - Programming - Mysql
: 2018-03-19Visitor Count : 164

Mysql


  1. Simple Replace
  2. Selected a string between two strings in a column in MYSQL
  3. Replaced a string between two strings in a column in MYSQL
  4. Copy Columns from One Table to Another
  5. Find duplicate records in MySQL
  6. Copy values from one column to another in the same table

Simple Replace

UPDATE Table SET `Column` = REPLACE(Column,'Find_String_Start', 'Replace_With')

Selected a string between two strings in a column in MYSQL

SELECT ID, Column, substr(Column, instr(Column,'Find_String_Start'), LOCATE('Find_String_End',Column,instr(Column,'Find_String_Start')+2)-instr(Column,'Find_String_Start') +2) as temp from Table where `Column` LIKE '%Find_String_Start%'

Replaced a string between two strings in a column in MYSQL

UPDATE Table SET `Column` = REPLACE(Column,substr(Column, instr(Column,'Find_String_Start'), LOCATE('Find_String_End',Column,instr(Column,'Find_String_Start')+2)-instr(Column,'Find_String_Start') +2), 'Replace_With') where `Column` LIKE

Copy Columns from One Table to Another

UPDATE `Table1`,`Table2`
SET  `Table1`.`column1` = `Table2`.`column1`
WHERE `Table1`.`column2` = `Table2`.`column3`
COLLATE utf8_unicode_ci

Find duplicate records in MySQL

 SELECT count(*), column
FROM Table
GROUP BY column
HAVING COUNT(*) > 1

SELECT column, COUNT(*) NewColumn FROM Table GROUP BY column DESC  HAVING NewColumn > 1  ORDER BY DESC COUNT(*)

Copy values from one column to another in the same table

INSERT INTO table2 (st_id,uid,changed,status,assign_status)
SELECT st_id,from_uid,now(),'Pending','Assigned'
FROM table1

 


   

2000-2016 CMS Fadak. ||| Version : 4.2-b1 ||| This page was produced in : 0.001 Seconds