Last active
January 30, 2017 22:54
-
-
Save mauricios/76bbcd2ffa7ada50bc3bd408a0fbd653 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a CSV with query results and save it to a file | |
SELECT * FROM table INTO OUTFILE '/var/lib/mysql-files/table.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ',' ESCAPED BY '"' LINES TERMINATED BY '\r\n'; | |
# Get selected fields and include a related field from other table | |
SELECT tableA.filed1, tableA.field2, tableB.filed1, tableB.field2 FROM tableA INNER JOIN tableB ON tableA.id = tableB.id; | |
# Filter fields with wildcard and order by a cetain field | |
SELECT * FROM table WHERE field1 LIKE '%@example.com' ORDER BY field2 | |
# Find unique duplicated records of a certain field | |
SELECT * FROM table GROUP BY field HAVING COUNT(*) >= 2; | |
# Find duplicated records of a certain field | |
SELECT field1, field2, table.field3 FROM table INNER JOIN (SELECT field3 FROM table GROUP BY field3 HAVING COUNT(*) > 1) dup ON table.field3 = dup.field3; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment