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 under
S151 - Introduction to SQL and MySQL [3269] Files or Databases? MySQL, SQLite, or Oracle? - (2011-04-28)
[2786] Factory methods and SqLite in use in a Python teaching example - (2010-05-29)
[2567] Extra MySQL course dates (2 day course, UK) - (2010-01-08)
[2561] The future of MySQL - (2010-01-03)
[2134] Oracle take over Sun who had taken over MySQL - (2009-04-21)
[924] The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13)
[918] Databases needn't be frightening, hard or expensive - (2006-11-08)
[691] Testing you Perl / PHP / MySQL / Tcl knowledge - (2006-04-19)
[515] MySQL - an FAQ - (2005-12-03)
[444] Database or Progamming - which to learn first? - (2005-09-13)
[382] Central London Courses - Perl, PHP, Python, Tcl, MySQL - (2005-07-18)
[175] Worthwhile - (2005-01-11)
[85] Present and future MySQL - (2004-10-12)
[84] MySQL - nuggets - (2004-10-11)
S152 - SQL Primer as Used in MySQL [3061] Databases - why data is split into separate tables, and how to join them - (2010-11-20)
[3060] INSERT, DELETE, REPLACE and UPDATE - changing the content of SQL tables - (2010-11-19)
[2240] How do I query a database (MySQL)? - (2009-06-15)
[502] SELECT in MySQL - choosing the rows you want - (2005-11-22)
[494] MySQL - a score of things to remember - (2005-11-12)
[270] NULL in MySQL - (2005-04-06)
[158] MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN - (2004-12-20)
S153 - Sourcing, Running and Configuring MySQL [2458] Cant connect to local MySQL server through socket /tmp/mysql.sock - (2009-10-17)
[2445] Securing MySQL on a production server - (2009-10-09)
[2444] Potted MySQL installation - (2009-10-09)
[2426] Which version of MySQL am I running? - (2009-09-26)
[2209] Monitoring and Tuning your MySQL installation - (2009-05-31)
[2085] MySQL - licensing issues, even with using the name - (2009-03-16)
[1935] Summary of MySQL installation on a Linux system - (2008-12-11)
[1771] More HowTo diagrams - MySQL, Tomcat and Java - (2008-08-24)
[1731] Apache httpd, MySQL, PHP - installation procedure - (2008-08-01)
[1689] Some sideways thoughts on the news - (2008-06-27)
[1131] MySQL - Password security (authentication protocol) - (2007-04-02)
[1123] mysqldump and mysqlrestore - (2007-03-30)
[1095] Apache httpd , browser, MySQL and MySQL client downloads - (2007-02-28)
[907] Browser -> httpd -> Tomcat -> MySQL. Restarting. - (2006-10-28)
[535] MySQL permissions and privileges - (2005-12-20)
[489] Which MySQL server am I using? - (2005-11-07)
[334] Symbolic links and hard links - (2005-06-02)
[192] Current MySQL and PHP paths and upgrades - (2005-01-28)
S157 - More MySQL commands [3270] SQL - Data v Metadata, and the various stages of data selection - (2011-04-29)
[2647] Removing duplicates from a MySQL table - (2010-02-22)
[2645] Optimising and caching your MySQL enquiries - (2010-02-22)
[2644] Counting rows in joined MySQL tables - (2010-02-22)
[2643] Relating tables with joins in MySQL - (2010-02-21)
[2448] MySQL - efficiency and other topics - (2009-10-10)
[2259] Grouping rows for a summary report - MySQL and PHP - (2009-06-27)
[2110] MySQL - looking for records in one table that do NOT correspond to records in another table - (2009-03-31)
[1904] Ruby, Perl, Linux, MySQL - some training notes - (2008-11-23)
[1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
[1574] Joining MySQL tables revisited - finding nonmatching records, etc - (2008-03-15)
[1331] MySQL joins revisited - (2007-09-03)
[1235] Outputting numbers as words - MySQL with Perl or PHP - (2007-06-17)
[1213] MySQL - the order of clauses and the order of actions - (2007-06-01)
[673] Helicopter views and tartans - (2006-04-06)
[581] Saving a MySQL query results to your local disc for Excel - (2006-01-29)
[572] Giving the researcher power over database analysis - (2006-01-22)
[567] Combining similar rows from a MySQL database select - (2006-01-17)
[517] An occasional chance, and reducing data to manageable levels - (2005-12-04)
[513] MySQL - JOIN or WHERE to link tables correctly? - (2005-12-01)
[449] Matching in MySQL - (2005-09-24)
[279] Getting a list of unique values from a MySQL column - (2005-04-14)
[159] MySQL - Optimising Selects - (2004-12-21)
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