Revisions
-
hofmannsven revised this gist
Jul 4, 2017 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -6,13 +6,13 @@ Getting started: - https://www.codecademy.com/courses/learn-sql Related tutorials: - [MySQL-CLI](https://www.youtube.com/playlist?list=PLfdtiltiRHWEw4-kRrh1ZZy_3OcQxTn7P) - [Analyzing Business Metrics](https://www.codecademy.com/learn/sql-analyzing-business-metrics) - [SQL joins infografic](https://lh4.googleusercontent.com/-RdjzcoAwBYg/UxTXWGJHgoI/AAAAAAAACrs/Gqbu6zyksgo/w852-h670/sql-joins.jpg) Tools: - [DataGrip](https://www.jetbrains.com/datagrip/) - [Sequel Pro](http://www.sequelpro.com/) Commands -
hofmannsven revised this gist
Jul 28, 2016 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -28,10 +28,14 @@ Create new database: `create database [database];` Select database: `use [database];` Determine what database is in use: `select database();` Show all tables: `show tables;` Show table structure: `describe [table];` List all indexes on a table: `show index from [table];` Create new table with columns: `CREATE TABLE [table] ([column] VARCHAR(120), [another-column] DATETIME);` Adding a column: `ALTER TABLE [table] ADD COLUMN [column] VARCHAR(120);` @@ -71,6 +75,8 @@ Deleting records: `DELETE FROM [table] WHERE [column] = [value];` Delete *all records* from a table (without dropping the table itself): `DELETE FROM [table];` (This also resets the incrementing counter for auto generated columns like an id column.) Delete all records in a table: `truncate table [table];` Removing table columns: `ALTER TABLE [table] DROP COLUMN [column];` Deleting tables: `DROP TABLE [table];` -
hofmannsven revised this gist
Mar 15, 2016 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,10 @@ Related tutorials: - Analyzing Business Metrics: https://www.codecademy.com/learn/sql-analyzing-business-metrics - SQL joins infografic: http://cd64.de/sql-joins Tools: - DataGrip: https://www.jetbrains.com/datagrip/ - Sequel Pro: http://www.sequelpro.com/ Commands ----------- -
hofmannsven revised this gist
Feb 26, 2016 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,9 +5,10 @@ Getting started: - http://www.sqlteaching.com/ - https://www.codecademy.com/courses/learn-sql Related tutorials: - MySQL-CLI: https://www.youtube.com/playlist?list=PLfdtiltiRHWEw4-kRrh1ZZy_3OcQxTn7P - Analyzing Business Metrics: https://www.codecademy.com/learn/sql-analyzing-business-metrics - SQL joins infografic: http://cd64.de/sql-joins Commands -
hofmannsven revised this gist
Feb 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -125,4 +125,4 @@ Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'l Find out the IP Address of the Mysql Host ----------- `SHOW VARIABLES WHERE Variable_name = 'hostname';` ([source](http://serverfault.com/a/129646)) -
hofmannsven revised this gist
Feb 5, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -125,4 +125,4 @@ Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'l Find out the IP Address of the Mysql Host ----------- `SHOW VARIABLES WHERE Variable_name = 'hostname';` ([source](http://serverfault.com/a/129646), contribution @junrillg) -
hofmannsven revised this gist
Feb 5, 2016 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -116,8 +116,13 @@ Rename column or table using an _alias_: `SELECT [table1].[column] AS '[value]', Users functions ----------- List all users: `SELECT User,Host FROM mysql.user;` Create new user: `CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';` Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'localhost';` Find out the IP Address of the Mysql Host ----------- `SHOW VARIABLES WHERE Variable_name = 'hostname';` ([source](http://serverfault.com/a/129646)) -
hofmannsven revised this gist
Feb 5, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -39,6 +39,8 @@ MySQL function for datetime input: `NOW()` Selecting records: `SELECT * FROM [table];` Explain records: `EXPLAIN SELECT * FROM [table];` Selecting parts of records: `SELECT [column], [another-column] FROM [table];` Counting records: `SELECT COUNT([column]) FROM [table];` -
hofmannsven revised this gist
Jan 8, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -74,6 +74,8 @@ Custom column output names: `SELECT [column] AS [custom-column] FROM [table];` Export a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysqldump -u [username] -p [database] > db_backup.sql` Use `--lock-tables=false` option for locked tables (more info [here](http://stackoverflow.com/a/104628/1815847)). Import a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysql -u [username] -p -h localhost [database] < db_backup.sql` Logout: `exit;` -
hofmannsven revised this gist
Sep 18, 2015 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -97,6 +97,18 @@ Get average value: `SELECT AVG([column]) FROM [table];` Get rounded average value and group by `[category-column]`: `SELECT [category-column], ROUND(AVG([column]), 2) FROM [table] GROUP BY [category-column];` Multiple tables ----------- Select from multiple tables: `SELECT [table1].[column], [table1].[another-column], [table2].[column] FROM [table1], [table2];` Combine rows from different tables: `SELECT * FROM [table1] INNER JOIN [table2] ON [table1].[column] = [table2].[column];` Combine rows from different tables but do not require the join condition: `SELECT * FROM [table1] LEFT OUTER JOIN [table2] ON [table1].[column] = [table2].[column];` (The left table is the first table that appears in the statement.) Rename column or table using an _alias_: `SELECT [table1].[column] AS '[value]', [table2].[column] AS '[value]' FROM [table1], [table2];` Users functions ----------- -
hofmannsven revised this gist
Sep 18, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -97,7 +97,7 @@ Get average value: `SELECT AVG([column]) FROM [table];` Get rounded average value and group by `[category-column]`: `SELECT [category-column], ROUND(AVG([column]), 2) FROM [table] GROUP BY [category-column];` Users functions ----------- List all users: `select User,Host from mysql.user;` -
hofmannsven revised this gist
Sep 18, 2015 . 3 changed files with 29 additions and 13 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -76,4 +76,32 @@ Export a database dump (more info [here](http://stackoverflow.com/a/21091197/181 Import a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysql -u [username] -p -h localhost [database] < db_backup.sql` Logout: `exit;` Aggregate functions ----------- Select but without duplicates: `SELECT distinct name, email, acception FROM owners WHERE acception = 1 AND date >= 2015-01-01 00:00:00` Calculate total number of records: `SELECT SUM([column]) FROM [table];` Count total number of `[column]` and group by `[category-column]`: `SELECT [category-column], SUM([column]) FROM [table] GROUP BY [category-column];` Get largest value in `[column]`: `SELECT MAX([column]) FROM [table];` Get smallest value: `SELECT MIN([column]) FROM [table];` Get average value: `SELECT AVG([column]) FROM [table];` Get rounded average value and group by `[category-column]`: `SELECT [category-column], ROUND(AVG([column]), 2) FROM [table] GROUP BY [category-column];` User functions ----------- List all users: `select User,Host from mysql.user;` Create new user: `CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';` Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'localhost';` 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,8 +0,0 @@ -
hofmannsven revised this gist
Sep 18, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -55,6 +55,8 @@ Select records starting with `val` and ending with `ue`: `SELECT * FROM [table] Select a range: `SELECT * FROM [table] WHERE [column] BETWEEN [value1] and [value2];` Select with custom order and only limit: `SELECT * FROM [table] WHERE [column] ORDER BY [column] ASC LIMIT [value];` (Order: `DESC`, `ASC`) Updating records: `UPDATE [table] SET [column] = '[updated-value]' WHERE [column] = [value];` Deleting records: `DELETE FROM [table] WHERE [column] = [value];` -
hofmannsven revised this gist
Sep 18, 2015 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -45,13 +45,15 @@ Counting records: `SELECT COUNT([column]) FROM [table];` Counting and selecting grouped records: `SELECT *, (SELECT COUNT([column]) FROM [table]) AS count FROM [table] GROUP BY [column];` Selecting specific records: `SELECT * FROM [table] WHERE [column] = [value];` (Selectors: `<`, `>`, `!=`; combine multiple selectors with `AND`, `OR`) Select records containing `[value]`: `SELECT * FROM [table] WHERE [column] LIKE '%[value]%';` Select records starting with `[value]`: `SELECT * FROM [table] WHERE [column] LIKE '[value]%';` Select records starting with `val` and ending with `ue`: `SELECT * FROM [table] WHERE [column] LIKE '[val_ue]';` Select a range: `SELECT * FROM [table] WHERE [column] BETWEEN [value1] and [value2];` Updating records: `UPDATE [table] SET [column] = '[updated-value]' WHERE [column] = [value];` -
hofmannsven revised this gist
Sep 18, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,8 @@ Searching records for a word: `SELECT * FROM [table] WHERE [column] LIKE '%[valu Searching records for a word starting with [value]: `SELECT * FROM [table] WHERE [column] LIKE '[value]%';` Searching for words starting with `val` and ending with `ue`: `SELECT * FROM [table] WHERE [column] LIKE '[val_ue]';` Updating records: `UPDATE [table] SET [column] = '[updated-value]' WHERE [column] = [value];` Deleting records: `DELETE FROM [table] WHERE [column] = [value];` -
hofmannsven revised this gist
Sep 15, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ Commands ----------- List all users: `select User,Host from mysql.user;` Create new user: `CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';` Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'localhost';` -
hofmannsven revised this gist
Sep 13, 2015 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,9 @@ MySQL =============== Getting started: - http://www.sqlteaching.com/ - https://www.codecademy.com/courses/learn-sql Related tutorial: http://cd64.de/mysql-cli -
hofmannsven revised this gist
Sep 13, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -66,4 +66,6 @@ Custom column output names: `SELECT [column] AS [custom-column] FROM [table];` Export a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysqldump -u [username] -p [database] > db_backup.sql` Import a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysql -u [username] -p -h localhost [database] < db_backup.sql` Logout: `exit;` -
hofmannsven revised this gist
Aug 11, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,4 +3,4 @@ Commands Create new user: `CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';` Grant `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'localhost';` -
hofmannsven revised this gist
Jul 3, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Commands ----------- Select but without duplicates: `SELECT distinct name, email, acception FROM owners WHERE acception = 1 AND date >= 2015-01-01 00:00:00` -
hofmannsven renamed this gist
Jun 14, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hofmannsven renamed this gist
Jun 14, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hofmannsven revised this gist
Jun 14, 2015 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ Commands ----------- Select but without duplicates: `SELECT distinct name, email, acception FROM owners WHERE acception = 1` -
hofmannsven revised this gist
May 28, 2015 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ Commands ----------- Create new user: `CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';` Grunt `ALL` access to user for `*` tables: `GRANT ALL ON database.* TO 'user'@'localhost';` -
hofmannsven revised this gist
Feb 19, 2015 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,8 @@ MySQL =============== Getting started: http://www.sqlteaching.com/ Related tutorial: http://cd64.de/mysql-cli SQL joins infografic: http://cd64.de/sql-joins -
hofmannsven revised this gist
Nov 8, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -52,6 +52,7 @@ Updating records: `UPDATE [table] SET [column] = '[updated-value]' WHERE [column Deleting records: `DELETE FROM [table] WHERE [column] = [value];` Delete *all records* from a table (without dropping the table itself): `DELETE FROM [table];` (This also resets the incrementing counter for auto generated columns like an id column.) Removing table columns: `ALTER TABLE [table] DROP COLUMN [column];` -
hofmannsven revised this gist
Nov 8, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -51,6 +51,8 @@ Updating records: `UPDATE [table] SET [column] = '[updated-value]' WHERE [column Deleting records: `DELETE FROM [table] WHERE [column] = [value];` Delete *all records* from a table (without dropping the table itself): `DELETE FROM [table];` Removing table columns: `ALTER TABLE [table] DROP COLUMN [column];` Deleting tables: `DROP TABLE [table];` @@ -61,4 +63,4 @@ Custom column output names: `SELECT [column] AS [custom-column] FROM [table];` Export a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysqldump -u [username] -p [database] > db_backup.sql` Logout: `exit;` -
hofmannsven revised this gist
Sep 11, 2014 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ [mysqld] max_allowed_packet=64M -
hofmannsven revised this gist
Aug 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -59,6 +59,6 @@ Deleting databases: `DROP DATABASE [database];` Custom column output names: `SELECT [column] AS [custom-column] FROM [table];` Export a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysqldump -u [username] -p [database] > db_backup.sql` Logout: `exit` -
hofmannsven revised this gist
Aug 3, 2014 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ SQL joins infografic: http://cd64.de/sql-joins Commands ----------- Access monitor: `mysql -u [username] -p;` (will prompt for password) Show all databases: `show databases;` @@ -59,4 +59,6 @@ Deleting databases: `DROP DATABASE [database];` Custom column output names: `SELECT [column] AS [custom-column] FROM [table];` Export a database dump (more info [here](http://stackoverflow.com/a/21091197/1815847)): `mysqldump -u [username] -p [database] > db_backup.sql` (will prompt for password) Logout: `exit`
NewerOlder