MySQL inner join vs left join

I wanted to make a super simple, cliff-notes-style introduction to inner joins and left joins, two of the most common joins you’ll encounter in MySQL-type relational databases. I always forget what they mean, so this is for me too. This is basically a condensed version of this wikipedia article.

All code in this post will use this sample database:

Employees can be assigned to departments. A department can have more than one employee, but an employee can only be in one department, or unassigned. Notice that one department, Marketing, has no employees assigned, and one employee, Williams, is not assigned to any department (signified by NULL in his DepartmentID column).

Joins compare all the rows in one table (the “left” table) against all the rows in another table (the “right” table), and let you ask meaningful questions that span multiple tables. An ON condition is used to specify what constitutes a “match” between any two rows picked from either table. In this post, the employee table will be the left table, and the department table willbe the right table, and all of our joins will use the ON condition where the DepartmentID matches between the two tables.

The output can then modified by the SELECT clause of the query, as usual, but all of the examples will use SELECT * for simplicity.

Left Join – “What department, if any, are my employees assigned to?”

In a left join, there will be a row in the output for each row in the left table, the table before the JOIN statement. The engine compares each row in the left table against each row in the right table and fills in the values based on the results of the ON condition.

SELECT *
FROM employee 
LEFT JOIN department 
ON employee.DepartmentID = department.DepartmentID;

The above query produces the following output:

Notice there is a row in the output for every employee, including the unassigned one, Williams, since employee is the left table in the join (appears before the JOIN keyword). For each employee, the engine finds the corresponding row in the department table, where the ON condition is met, where they have the same DepartmentID. For assigned employees, the output will contain all values from both rows.

However, for Williams’ row, the ON condition is not met. His DepartmentID is NULL, so there is no corresponding row in the department table to use in the output. Since this is a LEFT JOIN, the engine fills in the output values with NULL.

Notice also that the department with no employees, Marketing, does not show up in the output. This is because department is the right table in the join, and not every row in the right table is guaranteed to show up in the output in a LEFT JOIN. There was no employee row pointing to it, so it gets left out of the output.

This query answers the question “What department, if any, are my employees assigned to?” with NULL values signifying “none”.

Inner Join – “What department are my employees assigned to, excluding unassigned employees and empty departments?”

In an inner join, there will only be a row in the output if the ON condition is satisfied for both the left and the right tables.

SELECT *
FROM employee
INNER JOIN department
ON employee.DepartmentID = department.DepartmentID;

The above query produces the following output:

Notice this time there is no row in the output for the unassigned employee Williams OR the empty department Marketing. When the engine compares Williams’ row to the department table, it again finds no corresponding row where both DepartmentIDs satisfy the ON condition, where they are equal. Rather than fill in the missing values with NULL, it drops the row from the output completely. When the engine finishes comparing each employee row against the department table, again, Marketing was not used, and so it does not appear in the output either.

This query answers the question “Show me details of all employees that are assigned to a department, and details of said department”. It also answers the question, “Show me details of all departments with assigned employees, and details of said employees”.

Right Join – “What employees, if any, do my departments contain?”

I’m not going to go into it in-depth, as I haven’t seen it much in production, there is a corresponding right join to match the left join, where each row in the right table produces a row in the output, and the rest of the values are filled in from the corresponding rows in the left table, or NULL if no rows in the left table can be found that match the ON condition.

Query and output:

SELECT *
FROM employee 
RIGHT JOIN department ON employee.DepartmentID = department.DepartmentID;

2019 JavaScript String.replace() regex vs substring

Having done a bunch of HTML5/js work recently, I was curious about regex performance, especially in trivial cases where the power of regular expressions is not needed and a simple string substitution would suffice. I see regexes being used and recommended all over the web for simple string search-and-replace operations, and I typically regard that as bad advice, opting for the simpler substring-based substitution in my own code. But that makes the assumption that browser regex engines are not optimized to recognize simple string substitutions and use the simpler algorithm.

So it was time for a benchmark! It’s really simple, just replacing one word with another in a sentence that only has one occurrence of the search word.

Here are my results on Windows 10 across Edge, Firefox, and Chrome:

I was not surprised to see regex be from 75-97% slower in Firefox and Edge… but I was surprised to see regexes be 75%+ faster on Chrome!! That V8 regex engine must be highly optimized for simple regex cases!

I created a jsperf test case here – feel free to try it yourself and let me know what you get!

Documentation for String.replace() is here.

JS OOP Cheatsheet

Assume you have a JavaScript class, Car. You can create an instance of it:

new Car()

It’s really just a constructor function:

function Car() {}

Then:

  • Car.prototype.method is an instance method.

  • this.var inside Car() constructor or an instance method is an instance variable.

  • Car.var is a static (class-level) variable.

  • Car.method is a static method.

Borderlands 2 SHiFT Codes for Golden Keys on PC

xkcd

Following my normal pattern, I’m playing Borderlands 2 on PC in 2019. Here are all the SHiFT codes I’ve found online that still work (updated 2019-03-29) that gives you golden keys (which give you purple loot!). I’ve removed the hyphens because copy/paste doesn’t work in the game itself with the hyphens.

Golden key codes:

This code from the BL3 announcement gives you 100 keys!!

C3W33RZ6ZJTFJ6CTTJ33RFHX5

BL3 announcement code that gives you 5 keys and Salvador’s Community Day Skin:

C35TBWS6STTXBRKTTTJTJJH6H

These 3 codes together give you 70 keys:

5BW3BF96CTKXJFKTB3B339BWZ
WBK3TBKW6TTXTRKJTTBTC6BS5
W3KJBH9CBWXRBRWJTBTJ9JRXK

These codes each give you from 1 to 10 keys:

5TWJ3S5C9TXX3RW3JTTTSTXRJ
5TKBTRCW936XT65BTBBTXJZCH
KBWJJWTXB9C59J6WFBTJTK6BJ
CTWTBJTBW5KFTTTJTB33JTBWB
5T5B3CWJSKKRTJTTTJJT9HW63
KJ5BTFBKSKKXJ3T3BTJTFJX5C
KTK3JJWT6XKB65T3JJ3JWHBRT
C3WBBW3BRR5J6WB3JJJJ35ZKZ
WTWJ3TSXZSFTJB33TTJJWBCT3
WTKJ39JXZ96TJJB33T3JFRJC6
WTCTJJ9CS9RJJ33T3J3BBT9XH
WJW3B5HBR65BXCT33TJ3WXT53
WBCJBB3HHZRJJJJJJT3B69XHK
WB5JJKX6HSXBJBTTBJJBXW3S3
W3KJJKJXHZ6JJBJ3TT3T33XBR
W3CTJBFTFRKJRK3JJT3JH6H36
W3CB3RXRXBTFBR5BBT3TF3KXS
W353B9FXZZRBJ3JBT3B3JK9KH
KT5T3HS6HZFBJT33TJT3ZC5KH
KJ53BRRRSZF3TJJTJTT3WBHT6
KBKJBS5FSZFTTTTTJJJBXC95X
KB5BJWCRZ96J33JBBJ3TXK96K
K3WTTTKRH9X3BJTBJTBTKXTSB
K3WJTBFBRWS5RTTTBBB39XWZ5
K3WBTZ95HZFTT3JBTTJBZFX63
K3K333W9JT6XJJTTB3JBHWZZF
K3CTTSF6XTB6JXKTBJBT9KZZJ
K3CB33JF99RJ3JBJJ3JJBT3RX
K35TJ6399HXTBBT33TJBZZ3BX
K353BTWSBXH5BR5J3T336XTCK
CTW33J5KZBX6TFCJ3BTBFJ33H
CTC3J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JSZX55BB3BJ3HSRB6 (Axton’s Natural Twenty skin)
535BB3R3BZHF5K3JJB333BF3J (Gaige’s Summoner Sickness Skin)
CTKJ39CBJS9R5WTJBJ3TWKXKF (Zero’s The Pandora Chainmail Massacre skin)
CBCJ3W5TT9S65K3BJJ3BXHWWC (Maya’s Her Violent Nature skin)
CBKJ35FT39ZRCCTJTJB3RFJ5B (Krieg’s My Fantasies Involve Blood skin)
5J5TTRCJBSZXWCJTJ3BJTK3FB (Salvador’s Bear Naked skin)

Heads

KJKJTWHBKXHC9BTTJBJ3XJFSJ (Axton's Warrior of Light head)
CBKBJ6ZJW6HKH3TB3T33F5ZRS (Gaige's Wayfarer Wizard head)
CT5BBXTW5X9CSBT3BTTJFT5X5 (Zer0's G0ry Gh0ul head)
KTC3TWTW5FZCHB3BT3B3XJ9WR (Maya's Elven Eliminator head)
CBKBBZHJC6SWHJTJJ3BB3CXHS (Krieg's My Ears Are Ringing head)
WBCJJ33KWRS5Z33BJTTB65WJJ (Salvador's The Beast Within head)

Hip stabilizing exercises

The hips are super central to almost everything we do as humans. These exercises will help stabilize them so they can help you do everything you need to do in life.

Each exercise can be done in sets of as many reps as you’d like. Every body is different so I won’t prescribe a specific number of repetitions, but shooting for 10 is often a good goal. Always listen to your body and adapt as needed if an exercise is too hard!

Hip Raises

For this exercise, you stand on one foot. You can elevate if you want so the free foot can dangle below the ground plane, or just do it on solid ground if that makes you more comfortable. Use the hip of the leg you’re standing on to gently rotate the body until the free hip is comfortably higher than the hip of the leg you’re standing on. Make sure to relax the rest of the body and don’t attempt to lift the dangling leg using your side muscles. Do as many reps as feels good. Repeat on both sides.

hip raise

Single-leg Romanian Deadlift

This exercise really tests your balance! I am still not very good at doing this one without falling over :P. Stand straight with hands at sides, and gradually lower your torso, keeping the spine straight, while you extend one leg behind you for balance. Get as close to horizontal as you can, and then come back up. If your hamstrings are too tight to get to horizontal (like mine!), you can optionally bend your legs a little, this will let you go lower than a strict straight-leg deadlift. Make sure to stop when you feel a comfortable stretch in the hamstrings, don’t push too far and risk injury. Do as many reps as feels comfortable, and make sure to do the other side as well!

romanian deadlift

Single-leg Glute Bridge

For this exercise, lie on your back, with one foot on the floor, with the knee bent, holding the other knee to your chest. Gently raise your butt up using the glute on the side of the leg on the floor. Pay attention to where you feel the effort, you should feel it in the glute, and not in your back. Do as many reps as feels comfortable, and repeat on both sides.

single leg glute bridge 1

single leg glute bridge 2

Big Leg Circles

For lack of a better idea, we’re calling these ones big leg circles. Start with your leg crossed in front of you and slowwwwwwly trace as big of a circle as you can, all the way around until your leg is behind you. Adapt to your needs! Don’t pull anything! I can’t really do this one yet as pictured, my circles are MUCH smaller :). Do as many reps as feel comfortable and repeat on both sides.

Strengthening Intrinsic Muscles in the Foot

There are a whole bunch of little muscles and bones in the feet. They are marvels of engineering, they can bend and adapt in countless ways. Unfortunately, in our modern world, we spend a lot of time walking on flat surfaces, with our feet locked in place in stiff shoes, and so these muscles are often weaker than they should be. This can make everyday activities more difficult, to say nothing of running long distances.

These exercises aim to help strengthen the little stabilizing muscles in the feet and ankles, and improve balance. Do one or more sets of as many reps as feels comfortable to you.

Calf Raises: Straight Leg

Straight forward – the standard. Raise up on your toes, putting your weight on the balls of your feet, keeping knees and torso straight.

straight knees straight forward

Outward – raise up on your toes, putting your weight on the outside of the balls of your feet.

straight knees straight forward

Inward – raise up on your toes, putting your weight on your big toes.

Onto heels – lift your toes off the ground, putting your weight on your heels.

You can also try these on one leg for more intensity!

Calf Raises: Bent Leg

Keep knees statically bent a little. This uses different muscles than the straight-leg calf raises, and makes it harder.

Straight forward – the standard. Keep weight in the middle of the balls of your feet.

bent knees straight forward

Outward – same as before, but with bent knees.

Inward – same as before, but with bent knees.

Onto heels – same as before, but with bent knees.

Ankle Rolls

Roll out – standing up with straight legs, roll your ankles carefully outward, not going past the limit of your flexibility.

ankle roll out

Roll in – carefully roll your ankles inward. You won’t be able to go as far as outward, be very careful to not push too far. This will help you keep from spraining your ankle in the event that you DO roll your ankle.

Toe Grabbing

Sit on floor and grab coat with toes, flex foot down and inward, let go and repeat. This helps toe dexterity.

grab coat with toes

Spread out coat with toes – the opposite motion to the previous one, push out with your toes and try to spread a coat out on the floor.

Arch Flexes

Arch flexes: put the heel and ball of your foot on the floor, lift your arch and push the ball of the foot into the floor. Your toes can come up off the floor but don’t let them clench. This will help strengthen your arches.

arch flex

Miscellaneous

  • Standing/rolling on styrofoam dome, made from half a styrofoam ball.
  • Japanese kneel with toes bent up

ASUS Q550LF 15″ laptop SSD upgrade

I’ve had this laptop for several years, and it’s started getting sluggish, so I thought I’d upgrade it to an SSD to speed it up. It’s a nice laptop, aluminum body, i7 processor, 8GB RAM (also on the upgrade list), 1TB HDD (which is what I swapped out today).

The biggest issue was it required a #4 torx screwdriver to get the back plate off. These things are tiny!

I had to buy a new set of precision screwdrivers to get a small enough screwdriver.

With the tiny screwdriver I was able to remove the 10 screws holding the back plate on.

The hard drive is in the bottom left. Four small philips screws hold it in.

At this point I realized I had to remove the battery in order to get enough play in the SATA ribbon to disconnect the hard drive. Three Phillips screws hold it in.

It’s kind of small.

With the battery out of the way, I can lift up the hard drive.

After carefully disconnecting it from the SATA ribbon, it will take removing four more Phillips screws to separate the drive from its caddy.

So many tiny screws.

Now I can put the SSD in the caddy and work backwards, attaching it with four screws.

Completing the steps in reverse order puts it back together again. I connect the SATA ribbon, use four screws to secure the drive in its caddy, three to put the battery back in, and finally back to the torx screwdriver to put the back plate back on.

I fire it up, and windows is decidedly much faster to boot up now :). Everything looks good to go!

I had previously cloned my hard drive to the SSD. I used a SATA-to-USB adapter cable and a flash drive with Clonezilla on it to do the clone. Maybe I’ll do a write-up on that process sometime.

To finish off, here’s a picture of my little “helpers” :). Hope that helps!

Opt-in to Amazon Live App Testing

You’ve been invited to test an app for the Amazon Appstore, but the developer has informed you that your Amazon Account is opted out of Amazon marketing communications so your invitation email never arrived.

Here’s how to opt back in to just the one category Amazon requires so you can proceed with the test.

Click on this link.

Expand the dropdown next to “Promotional Emails” in “Email Preferences”

Make sure “Amazon Appstore” is checked and click “update”.

Let your developer know and they’ll send you a new testing invite.

Solution originally found here.

AGAL Error #3613: The native shader compilation failed

What a cryptic error message, yeah? Good grief! Thanks Adobe! Googling didn’t come up with very much, either.

Turned out I was passing two constant registers to an operation.

So basically, in order to compare two temporary registers, you have to copy one of them to a temporary register first.

This code failed in my vertex shader:
ife vc7.x, vc5.x

But this code works:

mov vt1, vc7
ife vt1.x, vc5.x

Go figure. Wonder why that is. Solution found on a comment on this article.

Photoshop – find opacity of semi-transparent pixel

Ever had an image open in photoshop with semi-transparent pixels and you needed to know the alpha value of those semi-transparent pixels? Turns out photoshop can do it, it’s just hidden by default. To enable this feature, open the Info window, choose Panel Options and then set the Second Color Readout mode to Opacity. Now when you use the color dropper tool and mouse over a semi-transparent pixel it will show you the opacity as a percentage as well as the color.

Screenshot 2016-04-25 14.00.46

Solution found here, duplicated here for link rot protection.