{"id":286,"date":"2018-10-29T19:46:11","date_gmt":"2018-10-29T19:46:11","guid":{"rendered":"https:\/\/jmrowe.com\/blog\/?p=286"},"modified":"2018-10-29T23:37:26","modified_gmt":"2018-10-29T23:37:26","slug":"mysql-notes","status":"publish","type":"post","link":"https:\/\/jmrowe.com\/blog\/mysql-notes\/","title":{"rendered":"MySQL Notes"},"content":{"rendered":"<p>Notes for a refresher and or quick reference for SQL.<\/p>\n<p>JOIN chart for visualizing the different types of possible JOIN.  Source: https:\/\/www.w3schools.com\/sql\/sql_join.asp<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/sql-join-notes.png\" alt=\"\" width=\"883\" height=\"362\" class=\"alignnone size-full wp-image-287\" srcset=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/sql-join-notes.png 883w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/sql-join-notes-300x123.png 300w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/sql-join-notes-768x315.png 768w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/sql-join-notes-624x256.png 624w\" sizes=\"auto, (max-width: 883px) 100vw, 883px\" \/><\/p>\n<p>Source from below: https:\/\/www.codeproject.com\/Articles\/33052\/Visual-Representation-of-SQL-Joins<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/Visual_SQL_JOINS_V2.png\" alt=\"\" width=\"600\" height=\"472\" class=\"alignnone size-full wp-image-290\" srcset=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/Visual_SQL_JOINS_V2.png 600w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2018\/10\/Visual_SQL_JOINS_V2-300x236.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>For a INNER JOIN , it can be re-written as such below and is called an IMPLICIT INNER JOIN<\/p>\n<pre class=\"lang:mysql decode:true \" >\r\nSELECT *\r\nFROM TableA A, TableB B\r\nWHERE A.Key = B.Key\r\n\r\nabove is the same as \r\n\r\nSELECT *\r\nFROM TableA A\r\nINNER JOIN TableB B\r\nON A.Key=B.Key\r\n\r\nUsing INNER JOIN is convention. INNER is also not needed as all joins are inner joins unless specified.\r\n<\/pre>\n<p>There is no difference between RIGHT JOIN and RIGHT OUTER JOIN. Both are the same. LEFT JOIN and LEFT OUTER JOIN  are also the same.<\/p>\n<p>IFNULL function. If it is going to return a NULL value you can set a replacement value instead. Useful for LEFT\/RIGHT JOINS where a column maybe be NULL<\/p>\n<p>So for example:<\/p>\n<pre class=\"lang:mysql decode:true \" >SELECT first_name,\r\n       last_name,\r\n       IFNULL(SUM(amount),0) AS total\r\nFROM customers\r\nLEFT JOIN orders\r\n       ON customers.id=orders.customer_id\r\n\r\n\/\/ If there is no orders found for a particlur customer.id, it will\r\n\/\/ return 0 for total instead of NULL<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Notes for a refresher and or quick reference for SQL. JOIN chart for visualizing the different types of possible JOIN. Source: https:\/\/www.w3schools.com\/sql\/sql_join.asp Source from below: https:\/\/www.codeproject.com\/Articles\/33052\/Visual-Representation-of-SQL-Joins For a INNER JOIN , it can be re-written as such below and is called an IMPLICIT INNER JOIN SELECT * FROM TableA A, TableB B WHERE A.Key = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-286","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/comments?post=286"}],"version-history":[{"count":8,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions"}],"predecessor-version":[{"id":297,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/286\/revisions\/297"}],"wp:attachment":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/media?parent=286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/categories?post=286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/tags?post=286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}