Skip to content

Instantly share code, notes, and snippets.

@supermensa
Created October 6, 2015 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermensa/7c660580953a9562d5a7 to your computer and use it in GitHub Desktop.
Save supermensa/7c660580953a9562d5a7 to your computer and use it in GitHub Desktop.
MySQL
Below are the most used MySQL commands:
For creating a table:
CREATE TABLE example (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER);
To grab everything from the table
SELECT * FROM example;
To get the number of rows from the table
SELECT COUNT(1) FROM example;
To insert a row into the table
INSERT INTO example (name, age) VALUES (‘veer’, 27);
To delete the row from the table
DELETE FROM example WHERE name = ‘veer’;
Updating a record
UPDATE example SET age = 30 WHERE name = ‘veer’;
Fetching rows on some condition
SELECT * FROM example WHERE name LIKE ‘%veer%’;
Fetching rows on multiple conditions
SELECT * FROM example WHERE (name LIKE '%veer%') AND (age > 25);
Fetching data only for selected fields
SELECT name, age FROM example where age > 25;
Explaining the execution plan of the query. It’s particularly useful if you need to figure out why a query is so slow.
EXPLAIN SELECT * FROM example;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment