Main Content

Key facts - SQL and MySQL

Archive - Originally posted on "The Horse's Mouth" - 2006-02-04 06:01:20 - Graham Ellis

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.