martes, 26 de octubre de 2021

MYSQL display duplicated values

SELECT      list_phone,list_name,COUNT(list_phone) FROM     lists where list_name='4thbatch-phoneonly' GROUP BY list_phone HAVING COUNT(list_phone) > 1;



| 9896652563 | 4thbatch-phoneonly |                 3 |

| 9896895556 | 4thbatch-phoneonly |                 3 |

| 9897435168 | 4thbatch-phoneonly |                 3 |

| 9897529384 | 4thbatch-phoneonly |                 2 |

| 9898399391 | 4thbatch-phoneonly |                 4 |

| 9898457427 | 4thbatch-phoneonly |                 2 |

| 9898766241 | 4thbatch-phoneonly |                 2 |

| 9898927972 | 4thbatch-phoneonly |                 3 |

+------------+--------------------+-------------------+

1943 rows in set (0.10 sec)


https://www.mysqltutorial.org/mysql-find-duplicate-values/


martes, 31 de agosto de 2021

subqueries

 SELECT (SELECT COUNT(*) FROM campaigns) as Campaigns, (SELECT COUNT(DISTINCT(list_name)) FROM lists where list_name!='TESTLOCAL' ) as list




You can do it by using subqueries, one subquery for each tableCount :

SELECT
  (SELECT COUNT(*) FROM table1 WHERE someCondition) as table1Count, 
  (SELECT COUNT(*) FROM table2 WHERE someCondition) as table2Count,
  (SELECT COUNT(*) FROM table3 WHERE someCondition) as table3Count

https://stackoverflow.com/questions/3761240/count-from-multiple-tables-in-mysql

jueves, 26 de agosto de 2021

create user and assign select permission to specific DB

 CREATE USER 'webdev'@'localhost' IDENTIFIED BY 'M1212';


GRANT SELECT ON dialer.* TO webdev@localhost IDENTIFIED BY 'M1212';


https://stackoverflow.com/questions/20036547/mysql-grant-read-only-options

viernes, 22 de enero de 2021

delete records on 2 table

delete all tables data

 DELETE cdr,campaigns FROM cdr INNER JOIN campaigns ON campaigns.cp_name = cdr.call_cp WHERE cdr.call_cp =campaigns.cp_name


delete all records from table cdr and campaigns where where campaigns.cp_name and  cdr.call_cp is equal A

DELETE cdr,campaigns FROM cdr INNER JOIN campaigns ON campaigns.cp_name = cdr.call_cp WHERE cdr.call_cp ='A';


MYSQL tutorial

 MYSQL tutorial


https://www.mysqltutorial.org/