Checking for a Null value in SQL

Yesterday I fell into a very simple but dangerous SQL trap.  Can you identify it?

SELECT first_column, another_column
FROM my_table
WHERE first_column = 1
    AND (another_column >= 100 OR 
         another_column = null)

Found it?  It’s the comparison to null.  My intention was to get rows where another_column was null, however the query did not do so.  It didn’t give me any results where another_column was null, but didn’t give me any error either.  Why?

Null in SQL is not a real value.  Null means “lack of a value” or “unknown”. Anything compared to null leads to an “unknown” result. Therefore, in SQL there are actually three values conditions can evaluate to: true, false, and unknown/null. This is called three-valued logic. SQL WHERE clauses only return rows that evaluate to true, not rows that evaluate to false or “unknown”.

The proper way of checking for null is by using the IS NULL or IS NOT NULL predicates. The correct SQL query would have been as follows:

SELECT first_column, another_column
FROM my_table
WHERE first_column = 1
    AND (another_column >= 100 OR 
         another_column IS null)

So if you’re used to languages where you check for null with equal signs, remember that in SQL, you must use the special IS NULL or IS NOT NULL predicates instead of the equals sign or other comparison operators. Don’t get tripped up like I did.

If you want to read more about, Wikipedia has a detailed article on null in SQL.

The hello world hackathon project

This past week, the co-op students at A Thinking Ape participated in an internal hackathon where they had two days to develop something to show the rest of the company.

Among the games and tools that resulted, one project stood out to me: a hello world app.  Yes, a hello world app. (For those not in the software development field, “hello world” is usually the first output that developers code when trying out a new platform or language.)

It had a white background, black text that said “Hello World,” and a green button that was labeled, “I am a button.”  It was built using Microsoft’s latest platform that supports writing universal Windows apps that can be run on Windows phones, tablets, and desktop computers.

What stood out to me was the way he presented this simple app.  He described the app not as any other hello world app, but one with a button and that it was green!  As he went on, he told us that the green button was also “self aware,” because it was labeled describing itself as a button.

Then he went on to clicking the button.  The text that appeared below said, “You clicked the button, ” or something to that effect.  He described this like predicting the future, but in reverse!

He finally proceeded to show us that how it looked on a phone simulator.

By the end of it, many of us were quite entertained by the way this seemingly simple and ordinary project was described.  This presentation reminded me of the  “reality distortion field” Steve Jobs had when he presented his keynotes (here’s one when Steve Jobs revealed Safari for Windows in 2007).

This example is to show that no matter what kind of product you have, the way you present it to people and the way you market it has a great effect on what the audience will feel and remember about the product.

Make Word spell check uppercase words

It’s a little known fact that Microsoft Word by default does not spell check uppercase words.  I had the opportunity to read through many co-op resumes from a couple universities this past week, and the typos I’ve seen seem to support this observation.

The problem comes when you have a section heading in capitals, such as “ACHIVEMENTS” or “RELEVENT SKILLS”.  Microsoft Word by default doesn’t indicate that the spelling is wrong!

I’m not sure why this “feature” is enabled by default, as I’d think it would be better to have more false positives than to have typos go undetected.  In any case, it’s easy to get Word to spell check uppercase words, which I’ll outline below.

More importantly it’s essential to manually proofread your job applications.  Having typos (among other things) shows a lack of attention to detail.  Don’t rely on an automated spell check.

Enable uppercase word spell check in Microsoft Word 2010 and 2007

  1. Open up Word Options.
    2010: Click the File tab, then Options.
    2007: Click the Office button at the top left, then click Word Options.
  2. Click the Proofing tab on the left.
  3. Deselect “Ignore words in UPPERCASE”.

word2007uppercase

Enable uppercase word spell check in Microsoft Word 2003 and older

  1. Click on the Tools menu, then click on Options.
  2. Click the “Spelling & Grammar” tab.
  3. Deselect “Ignore words in UPPERCASE”.

Enable uppercase word spell check in Microsoft Word 2011 and 2008 for Mac

  1. Click on the Word application menu, then click on Preferences.
  2. Click on the “Spelling & Grammar” icon.
  3. Deselect “Ignore words in UPPERCASE”.

word2011uppercaseHave you got other related tips and tricks to Microsoft Words, or resume writing?  Share yours in the comments.

How often do you see “Yay!” on packaging? (and a look at my workplace)

On Thursday, I found this on my desk after lunch.

Excited, I was!  Yay!  My first professional business cards!

There they are!

3 different coloured cards.  Green, blue and black.  I probably should have picked some more vibrant colours…

In case you were wondering what was in the “Yay!” package, it is a card holder.  To tell you the truth, I opened that one first because “Yay!” just sounded so exciting.

And here’s a glimpse of what it’s like at work:

The engineering floor. A nice lounge-y area in the middle. Pods of desks on either side. My desk is at the furthest pod in the photo.
My desk up close. Still relatively clean (hoping to keep it that way). Across from me is one of the co-founders/CEO.

Life of a new graduate

It’s the end of one era and a beginning of another.  Three weeks ago, I (finally) graduated with a B.Sc. in Computer Science, marking the end of my undergraduate student career.  Although it took six years, I think it was worth the time, especially the co-op work terms I did.  After all, it was my last co-op term at A Thinking Ape that got me my full-time position there.

I just finished my second week at A Thinking Ape, and so far it has been a blast.  The company doubled its size since I co-oped there last year and now has offices occupying the top two floors of a building in Gastown.  I was able to check in my first piece of code on the second day and got ramped up pretty quickly.

Will I miss school?  Probably yes.  School’s been a part of my life for the past 18 years.  Learning however doesn’t stop at graduation.  I am reminded of the motto of my elementary school: “Be a learner for life.”  This is true especially in the field of software, computers and technology; constant learning is required to keep up with the current trends.

So here I am, stepping foot into the “real world”.  Hello world!