Skip to content

Instantly share code, notes, and snippets.

@ranraj
Last active August 29, 2015 14:07
Show Gist options
  • Save ranraj/839036349ff03481eb53 to your computer and use it in GitHub Desktop.
Save ranraj/839036349ff03481eb53 to your computer and use it in GitHub Desktop.
Queries
##Select duplicate key on an column in mysql table with count
SELECT name, COUNT(*) c FROM CAT GROUP BY name HAVING c > 1;
## Simple table join queries
select a.* from CAT a,TAX b where b.name like '%Tax%' and a.PARENT_TAX_PKEY=b.pkey;
## Safe mode update Enable / Disable
SET SQL_SAFE_UPDATES = 0;
## Delete duplicate name records and keep lowest id record
DELETE n1 FROM CAT n1, CAT n2 WHERE n1.PKEY < n2.PKEY AND n1.name = n2.name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment