Category Archives: MySQL

MySQL JOINS…

Different SQL JOINs

Before we continue with examples, we will list the types of JOIN you can use, and the differences between them.

  • JOIN / INNER JOIN : Return rows when there is at least one match in both tables
  • LEFT JOIN : Return all rows from the left table, even if there are no matches in the right table
  • RIGHT JOIN: Return all rows from the right table, even if there are no matches in the left table
  • FULL JOIN: Return rows when there is a match in one of the tables

MySQL UPSERT (Insert or Update)


     $sql = "INSERT INTO postcode
                        (postcode,
                         lat,
                         lon,
                         osEasting,
                         osNorthing,
                         osRef6)
                        VALUES ('" . str_replace(" ", "", $data[0]) . "',
                                '" . round($lat,6) . "',
                                '" . round($lon,6) . "',
                                '" . round($data[2]) . "',
                                '" . round($data[3]) . "',
                                '" . $osref . "'
                                )
                        ON DUPLICATE KEY UPDATE
                                postcode   = '" . str_replace(" ", "", $data[0]) . "',
                                lat        = '" . round($lat,6) . "',
                                lon        = '" . round($lon,6) . "',
                                osEasting  = '" . round($data[2]) . "',
                                osNorthing = '" . round($data[3]) . "',
                                osRef6     = '" . $osref . "'";