Some quick ways to remember your SQL; here are some "flashbulb moments" for newcomers and occasional users of MySQL and other SQL databases.
A database daemon is a process that looks after a number of DATABASES each of which comprises a number of TABLES each of which comprises data arranges in ROWS and COLUMNS.
You don't access database information directly on the disc from any application program - you access it via your database daemon (a program called mysqld) which is usually running all the time and MUST be running whenever you want to access your data.
You SHOW to look at the structure but you SELECT to look at the content.
You UPDATE the content of table rows but you You ALTER the structure of a table.
You choose rows from a result set with a WHERE clause but you choose rows after you've grouped them with a HAVING clause.
You add tables to each other "side by side" with a JOIN and you add results sets above/below each other with a UNION.
You use a USE command (or other function call) to set the current DATABASE but there is no concept of current TABLE to carry through from one query to the next on a connection.
REPLACE gets rid of existing rows and puts new data in their place, but UPDATE changes existing rows in situe and leaves columns that you don't re-specify unaltered. DELETE gets rid of rows completely, and INSERT puts in completely new rows.
Every row in a table has the same structure (homogeneous) but different columns will have different structures (hetrogeneous).
If you JOIN tables, you tell MySQL how the tables are to be connected to each other (which row(s) in the first table match which row(s) in the second) using an ON clause.
A regular JOIN return only result rows where the ON clause matches up a row from each table exactly, and a LEFT JOIN return the same results and IN ADDITION any records from the left hand table specified, NULL padded to make a complete result record.
You use = to check whether something has an exact value, but you use IS NULL to check for the total absence of any defined value.
Some useful resources ...
See our
MySQL FAQ for further useful articles and the main MySQL web site for
the full MySQL reference manual.
We teach
private MySQL courses at our centre and we run
public courses too. If you've a group of trainees who all need the same course at the same time, we can run
a course at your office too.
We run a
user forum where you can ask questions to which you can't easily find the answer elsewhere, and we post up
longer articles in our solution centre. Further information is grouped by topic such as
SQL Primer,
more complex SQL commands,
MySQL installation and admin,
how to design a database and
writing applications to use a database.
(written 2006-02-04, updated 2006-06-09)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
S157 - More MySQL commands [158] MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN - (2004-12-20)
[159] MySQL - Optimising Selects - (2004-12-21)
[279] Getting a list of unique values from a MySQL column - (2005-04-14)
[449] Matching in MySQL - (2005-09-24)
[494] MySQL - a score of things to remember - (2005-11-12)
[502] SELECT in MySQL - choosing the rows you want - (2005-11-22)
[513] MySQL - JOIN or WHERE to link tables correctly? - (2005-12-01)
[515] MySQL - an FAQ - (2005-12-03)
[517] An occasional chance, and reducing data to manageable levels - (2005-12-04)
[567] Combining similar rows from a MySQL database select - (2006-01-17)
[572] Giving the researcher power over database analysis - (2006-01-22)
[581] Saving a MySQL query results to your local disc for Excel - (2006-01-29)
[673] Helicopter views and tartans - (2006-04-06)
[1213] MySQL - the order of clauses and the order of actions - (2007-06-01)
[1235] Outputting numbers as words - MySQL with Perl or PHP - (2007-06-17)
[1331] MySQL joins revisited - (2007-09-03)
[1574] Joining MySQL tables revisited - finding nonmatching records, etc - (2008-03-15)
[1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
[1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
[2110] MySQL - looking for records in one table that do NOT correspond to records in another table - (2009-03-31)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2448] MySQL - efficiency and other topics - (2009-10-10)
[2643] Relating tables with joins in MySQL - (2010-02-21)
[2644] Counting rows in joined MySQL tables - (2010-02-22)
[2645] Optimising and caching your MySQL enquiries - (2010-02-22)
[2647] Removing duplicates from a MySQL table - (2010-02-22)
[3061] Databases - why data is split into separate tables, and how to join them - (2010-11-20)
[3270] SQL - Data v Metadata, and the various stages of data selection - (2011-04-29)
[4481] Extracting data from backups to restore selected rows from MySQL tables - (2015-05-01)
S153 - Sourcing, Running and Configuring MySQL [192] Current MySQL and PHP paths and upgrades - (2005-01-28)
[334] Symbolic links and hard links - (2005-06-02)
[489] Which MySQL server am I using? - (2005-11-07)
[535] MySQL permissions and privileges - (2005-12-20)
[907] Browser -> httpd -> Tomcat -> MySQL. Restarting. - (2006-10-28)
[1095] Apache httpd , browser, MySQL and MySQL client downloads - (2007-02-28)
[1123] mysqldump and mysqlrestore - (2007-03-30)
[1131] MySQL - Password security (authentication protocol) - (2007-04-02)
[1689] Some sideways thoughts on the news - (2008-06-27)
[1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
[1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
[1935] Summary of MySQL installation on a Linux system - (2008-12-11)
[2085] MySQL - licensing issues, even with using the name - (2009-03-16)
[2209] Monitoring and Tuning your MySQL installation - (2009-05-31)
[2426] Which version of MySQL am I running? - (2009-09-26)
[2444] Potted MySQL installation - (2009-10-09)
[2445] Securing MySQL on a production server - (2009-10-09)
[2458] Cant connect to local MySQL server through socket /tmp/mysql.sock - (2009-10-17)
[4390] Checking MySQL database backups have worked (not failed) - (2015-01-10)
[4406] Fixing damaged MySQL tables - Error 1712 and Error 2013 - (2015-01-25)
[4487] Starting MySQL. ERROR! The server quit without updating PID file - how we fixed it. - (2015-05-06)
S152 - SQL Primer as Used in MySQL [270] NULL in MySQL - (2005-04-06)
[2240] How do I query a database (MySQL)? - (2009-06-15)
[3060] INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables - (2010-11-19)
[4007] Which database should I use? MySQL v SQLite - (2013-02-16)
S151 - Introduction to SQL and MySQL [84] MySQL - nuggets - (2004-10-11)
[85] Present and future MySQL - (2004-10-12)
[175] Worthwhile - (2005-01-11)
[382] Central London Courses - Perl, PHP, Python, Tcl, MySQL - (2005-07-18)
[444] Database or Progamming - which to learn first? - (2005-09-13)
[691] Testing you Perl / PHP / MySQL / Tcl knowledge - (2006-04-19)
[918] Databases needn't be frightening, hard or expensive - (2006-11-08)
[924] The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13)
[2134] Oracle take over Sun who had taken over MySQL - (2009-04-21)
[2561] The future of MySQL - (2010-01-03)
[2567] Extra MySQL course dates (2 day course, UK) - (2010-01-08)
[2786] Factory methods and SqLite in use in a Python teaching example - (2010-05-29)
[3269] Files or Databases? MySQL, SQLite, or Oracle? - (2011-04-28)
[3928] Storing your intermediate data - what format should you you choose? - (2012-11-20)
Some other Articles
Add a friendly front end with TkTwice is a co-incidence and three times is a patternFinding where the disc space has goneNOT Gone phishingKey facts - SQL and MySQLDanny and Donna are getting marriedRobust PHP user inputsChanging @INC - where Perl loads its modulesJob vacancy - double agent wantedPerl Regular Expressions - finding the position and length of the match