Monday, January 25, 2021

JOINs - The Basics

 JOINs confuse a lot of those new to Structured Query Language (SQL). If you read the various web forums popularly used to ask questions then you know that using JOINs is pretty scary for a lot of folks. The sheer number of the 'how do I use JOIN to link two tables together?' questions is staggering. Not just because the JOIN itself is often obfuscated with relational algebra, Venn Diagrams, and the syntactical oddities of SQL -- and that is when you do find an online resource that tries to help. Plus adding to the frustration on top of all that are that the various options for using JSON can be downright perplexing.

Example 1

Let us start with an example of customers and their orders.  There is one table named customer for the information pertaining to the customer. There is another table with order information named orders holding the details of any orders from those folks in the customer table. 

Each of these tables has a column for the identification number of a customer.  In the customer table that column is named id and in the orders table that column is named customer_id.  Besides the inconsistencies in plurals of the table names, which is all too common in databases, there is the difference in column names for what is essentially the same data.  If you can get past that issue and realize that that you can use either column to link to the other table, then you are almost ready for the 'tricky stuff'.

To find the list of orders and their correspond customer, we can JOIN the two tables using the id/customer_id columns between the table with a simple JOIN. 

SELECT
orders.order_id
, customer.id
, customer.name  
from orders 
join customer 
on (customer.id = orders.customer_id) ;

And the results show the data from the orders table with the corresponding data with customer table.

The results of JOIN






LEFT Joins

But sometimes the two tables do not always evenly match up.  If we change the query above from join customer to LEFT join customer we get a much different result.

The results of LEFT JOIN




The LEFT JOIN displays all the orders and the corresponding customer information, if any.  If there is no corresponding data for the customer information, the server reports NULL(1).  In this case NULL is used to represent that we have no data for that element and order number 2 does not have a matching entry in the customer table.

RIGHT Joins

Changing the query to a RIGHT join will display all the customers and an orders they may have placed.

The Results of a RIGHT JOIN




The above shows that two orders have been placed by customers 1 & 2 and no orders from the customers 3 & 4.

CROSS Join

A CROSS Join will match every row in the first table with every row in the second table. Notice that the query is modified with no ON statement.  

The revised query for a
CROSSJOIN and the results











STRAIGHT_JOIN 

The STRAIGHT_JOIN is used to force the left table to be read first in cases where the optimizer wants to change things around for you.  With optimizer hints, this maybe redundant but it is still very handy.


The STRAIGHT_JOIN









The Natural JOIN

The NATURAL join creates an implicit join clause on the common columns in the two tables being joined. Common columns are columns that have the same name in both tables which means that you need to be VERY certain the columns with the same names are actually using the same data -- You do not want the 'id' for customers to get confused with those from the orders, employees, or other tables.


The Natural Join










(1) NULL

Null is used to indicate the absence of data. If you go back to the second example. the LEFT JOIN, we received records where there was no matching customer id number or name.  This could be caused by bad data in the tables, a badly entered record, or many other (frustrating) causes.  But the records that are holding NULLs can be found.  Hopefully I can loop back to that at a later date.



Tuesday, January 5, 2021

MySQL 5.6 End of Life in ONE MONTH!!!

 For the past year or so I have been reminding folks that MySQL 5.6 reaches End of Life Status in ONE MONTH!!  No more updates or security fixes!  Nostalgia is a fine things and I like antiques but not for my database!

So if you are on 5.6 please upgrade to 5.7 -- https://dev.mysql.com/doc/refman/5.7/en/upgrading.html and consider going to 8.0 - https://dev.mysql.com/doc/refman/8.0/en/upgrading.html  plus there is a5.7 to 8.0 upgrade checker in the new shell - https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-utilities-upgrade.html

Friday, December 18, 2020

Holidays Gifts For Your MySQL DBA - 2020 Edition

 Dear Family, Friend, Co-Worker, or Acutance of a MySQL DBA,

You MySQL DBA knows that shopping for them this time of year is very hard as all they really need is a new instance of MySQL to make them ecstatic.   However they have downloaded this list of gifts, have printed this out, and circled some gift ideas from this blog -- to make it easier for you. 


1. Singing Tesla Coil Music Kit Plasma Loudspeaker Wireless Transmission Experiment Desktop 


Link

Musical Tesla Coil (also known as "Singing Tesla Coil"), sometimes called a zeusaphone, thoramin or musical lightning, is a form of plasma speaker. The music Tesla coil, It is a variety of a solid state Tesla coil that has been modified to produce musical tones by modulating its spark output. The resulting pitch is a low fidelity square wave like sound reminiscent of an analog synthesizer. The high-frequency signal acts in effect as a carrier wave; its frequency is significantly above human-audible sound frequencies, so that digital modulation can reproduce a recognizable pitch. The musical tone results directly from the passage of the spark through the air.

2. A new Cup


Link

Yes, a new mug is needed as we approach 2021!




3. Alternative Cup


Link

Maybe two new mugs! This time with a possibly naughty message!





4. Star Wars Death Star Popcorn Maker - Hot Air Style with Removable Bowl


HEALTHIER CHOICE - Uses hot-air popping method so no oil required. It makes popcorn a perfect snack for the whole family.

EASY OPERATION - Add kernels into the main chamber using the provided measuring cup, turn on the unit and watch the magic happen through the transparent cover!

HIGH EFFICIENCY - Pops evenly and quickly, with up to a 98% popping rate. Unique channel ensures constant hot air to pop about as quickly as a microwave (2-3 minutes).


5. A New Light Switch Cover


Link 

Change up that boring switch plate with something a little quirky!





6. A new blanket or pillow


Link 


Yes, that MySQL DBA needs at least one of these too!




7. New shirt


Link 

With the closing of many in person conferences, your DBA may be lacking in t-shirts so get them this one!






Monday, November 30, 2020

Running MySQL 5.6? It reaches End Of Live Status in TWO MONTHS

  This is yet another reminder that MySQL 5.6 reaches End of Life status in February 2021.  I have been sending out such reminders since February of 2020. But in my presentations this year when I bring up the 5.6 EOL, there are a lot of users out there that are shocked to hear the news. In one of my November presentations (virtual) I had a very upset audience member who wondered why I was not making more of a big deal out of the EOL date.

    Wikipedia says ""End-of-life" ("EOL") is a term used with respect to a product supplied to customers, indicating that the product is in the end of its useful life (from the vendor's point of view), and a vendor stops marketing, selling, or rework sustaining it. (The vendor may simply intend to limit or end support for the product.)" 

What does this mean those of you running MySQL 5.6 will not be getting bug fixes, will find it much harder to get support, and will get social ostracized by all. Well, maybe not that last one.  But you life is going to be tougher.  As someone who loves old cars I can attest that even the simplest of spare parts or practical repair knowledge on unique features gets much harder to find over time.  And like my buddy who still supports dBase II, you will find your world curtailed.

So please upgrade to MySQL 5.7 or better yet 8.0.   Those of you running 5.7 can use the upgrade checker utility to help you upgrade to 8.0.

Utah Oracle Users Group December 3rd presentation on New MySQL 8.0 Features

 Want to learn more about new features in MySQL 8.0? The folks at the Utah Oracle Users Group are opening their December 03, 2020 meeting to all.  It will run from 6:30 PM - 8:00 PM Mountain Time. 

Please RSVP https://us02web.zoom.us/j/89659298608?pwd=QVhIRDcvV0EwNnF




Wednesday, November 11, 2020

Live Events This Week and More Basic Videos

    The Granite State Code Camp is this Saturday November 14th and I will be speaking on new Features in MySQL 8.

    Sadly Babbletech is going to be canceled but you can catch my talk on MySQL Indexes and Histograms that was recorded at the All Things Open Conference. 

  And I am slowly adding more videos to my Dave's MySQL Basics series for beginners.  Please see them on Youtube or Github. If you have a subject you want to see sooner than I have planned, please let me know!

Monday, November 2, 2020

MySQL 5.6 End of Life Reminder

 This is a reminder that MySQL 5.6 reaches End of Life status in February 2021.  I have been sending out such reminders since February of this year. But in my presentations this year when I bring up the 5.6 EOL, there are a lot of users out there that are surprised to hear the news.

    Wikipedia says ""End-of-life" ("EOL") is a term used with respect to a product supplied to customers, indicating that the product is in the end of its useful life (from the vendor's point of view), and a vendor stops marketing, selling, or rework sustaining it. (The vendor may simply intend to limit or end support for the product.)" 

So those of you running MySQL 5.6 will not be getting bug fixes, will find it much harder to get support, and will get social ostracized by all. Well, maybe not that last one.  But you life is going to be tougher.  As someone who loves old cars I can attest that even the simplest of spare parts or practical repair knowledge on unique features gets much harder over time.  And like my buddy who still supports dBase II, you will find your world curtailed.

So please upgrade to MySQL 5.7 or better yet 8.0.   Those of you running 5.7 can use the upgrade checker utility to help you upgrade to 8.0.