Frames Modems Help Home Page Chipsets Search No Frames
Diary Entries See also Site Info & Diary.
15 December 2001 Finding “missing” records (MySQL LEFT JOIN on NULL values)...
  (See also MySQL 7.20 JOIN Syntax)

Finished entering all the modem & chipset Manufacturer names plus trade-marked names - essentially, completed this site's manufacturer's Index page. USR was an anomaly - it is the only active company which both makes modems & also makes the modem chipsets (although I think that ‘assemble’ is more correct than ‘make’ where the chipsets are concerned). As each /mfc/ record is essentially a separate page - all 149 of them at this stage - I decided to add another /mfc/ specifically for USR as a chipset manufacturer:

  UPDATE /mfc/ SET Name='USRchips', UsesID=1, Dead=NULL, Notes=NULL;
Did you spot the deliberate mistake? I used ‘UPDATE’ instead of ‘INSERT’, and set all 149 records to the same value (yet another sigh).

Turning to yesterday's backup rescued most of the changes, but left some records from the names table without a corresponding /mfc/. First, I needed to discover precisely which names had no /mfc/:

  select NID, names.Name, YID, names.MID, names.Dead from names
   LEFT JOIN /mfc/ ON names.MID=/mfc/.MID WHERE /mfc/.MID IS NULL;
It turned out to be 8 records - phew! (most of the additions had been into names, not /mfc/).

The MySQL manual explains that when there is no matching record in the RHS table in a LEFT JOIN (and presumably vice versa with a RIGHT JOIN) a row with all columns set to NULL is used for the right table, and hence the WHERE test. Next, the /mfc/ needed creating (using an INSERT this time) & fortunately the correct MID was created automatically. Finally, the new USR /mfc/ was created & the MID for the already-created USR names changed.

To complete this, this is the tally of records now created:

    150 Manufacturers
    533 Names
4 months to get this far, 3 tables only involved - /mfc/, names & nameTypes. Well, not too bad. I'm now comfortable with MySQL, Apache & PHP and the pages are getting constructed quicker & quicker. Plus, updating the info is immensely quicker (and smaller), which is the whole point.