Skip to content

Instantly share code, notes, and snippets.

@juliosguz
Last active August 29, 2015 14:11
Show Gist options
  • Save juliosguz/1934b3d820469a976f24 to your computer and use it in GitHub Desktop.
Save juliosguz/1934b3d820469a976f24 to your computer and use it in GitHub Desktop.
Tips for MySql queries
# When you need only 1 records, use Limit 1
SELECT * FROM default_users WHERE username='juliosguz' LIMIT 1;
# Try to not use undetermined functions like : RND(),NOW(),CURDATE() in your queries, because some times MySql disable cache for that
SELECT * FROM default_users WHERE birthday >= NOW(); # BAD
SELECT * FROM default_users ORDER BY RAND(); # BAD ++ !!!!
SELECT * FROM default_users WHERE birthday >= 1419032756; #GOOD , this value maybe you can get with time() function in php for example
# Avoid NULL fields in your tables
# Use MyISAM for reading table and InnoDB for writing tables
# For MyISAM , COUNT() works better but not INSERT/UPDATE/DELETE queries.
# For InnoDB , INSERT/UPDATE/DELETE queries works better.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment