Excluding NULL values when using NOT IN operator

Let’s see an example retrieving the elements exist in Table A but not in Table B first.

-- Input
-----------------------------------
select * 
from A
-----------------------------------
-- Output
----------
name
----------
Bing
Google
Yahoo
----------
-- Input
-----------------------------------
select * 
from B
-----------------------------------
-- Output
----------
name   
----------
Bing 
Yahoo
NULL
----------
-- Input
-----------------------------------
select name 
from A 
where name not in (
    select name 
	from B 
	where name is not null
)
-----------------------------------
-- Output
----------
name
----------
Google
----------
-----------------------------------

In the last query, if you remove “where name is not null” clause, you won’t get expected result. The reason is when comparing “Google” in Table A with Table B, the logic is equivalent to:
“Google” <> “Bing” (TRUE) and “Google” <> “Yahoo” (TRUE) and “Google” <> null (UNKNOWN)
This leads to UNKNOWN finally in WHERE clause so nothing will return. In a word, just remember to exclude NULL values when using NOT IN in WHERE clause.

Google Search Basics

“Keep it simple” is the general principle for Google search. That is to say, thinking of the words are most likely to appear on the page you are looking for, then choose the best descriptive words and keep them as few as possible. Also, the following basic rules you should keep in mind as well.

* square brackets [ ] to signal a search query in the examples below

  1. Generally all the words you put in the query will be used except the words are commonly used, like ‘the,’ ‘a,’ and ‘for,’.

  2. Search is always case insensitive.

  3. Generally punctuation and other special characters are ignored but some exceptions may apply.

  • Punctuation in popular terms that have particular meanings is not ignored.
    Example: [ C++ ] [ C# ]
  • The dollar sign ($) used to indicate prices is not ignored.
    Example: [ nikon $400 ]
  • The hyphen - and underscore symbol _ used to connect two words are not ignored.
    Example: [ quick-sort ] [ quick_sort ]
  1. By putting double quotes (“”) around a set of words, the exact words in that exact order are used in the search.

  2. Search could be within a specific website (site:).
    Example: [ iraq site:nytimes.com ] [ iraq site:.gov ]

  3. Attaching a minus sign (-) immediately before a word indicates that you want to exclude this word from the results. Example: [ anti-virus -software ] [ iraq -site:nytimes.com ]

  4. The wildcard (*) is treated as any unknown term(s) in a search.
    Example: [ Obama voted * on the * bill ]

  5. Google employs synonyms automatically. To avoid this feature, attaching a + immediately before a word. It is the same with putting double quotes (“”) around a single word.

  6. By default, the AND operator is used among the words. If you want to specify either one of several words, you can use the OR operator. (note that you have to type ‘OR’ in ALL CAPS).
    Example: [ San Francisco Giants 2004 OR 2005 ]

References

Firefox 4.0+ has performance problem with background-size property

Firefox starts supporting standard background-size property since 4.0. But unfortunately, it likely doesn’t render this property properly. If you are using Firefox 4.0+ or Chrome, you might have noticed the angled striped background on my site. The current background-size is:

body {
	...
	background-size: 100px 100px;
	...
}

If you change it to a smaller size with firebug or other tools on your browser, you would see the stripes get thinner. It works perfect on Chrome but DON’T do it on Firefox 4.0+, as if so it would cause Firefox hanging forever. I guess the algorithm Firefox is using to render background-size needs to be optimised for small size.

I found this problem because my ideal effect of my site is to use very thin stripes as background. If you are brave, try this beautiful but dangerous change on my site.

body {
 ...
 background-size: 5px 5px;
 ...
}

How to change the target of a symbolic link in Linux

The common way is to delete the original symlink then re-create it.

rm symlink; ln -s target symlink

But if you want to do it more conveniently and efficiently, you can force ln command to change the target of the soft link without deleting the old one explicitly. For example:

# original symlink
$ ln -s /path/to/target old_symlink

# change to the new symlink
$ ln -fs /path/to/target new_symlink

References

  • Linux Man pages

Stop git tracking your files

I’m a new git user. The question came up to me is after I created a git repository with git init, I suddenly changed my mind. That is to say, I don’t want git to track the directories and files in this repository but of course I don’t want to lose my work either. git itself don’t have a command for this situation but the fix is quit easy actually. As git keeps all of its files in the .git directory, what I need to do is just to remove it.

# Just make sure you are doing the right thing, because all info from git will lose after doing this.
$ rm -rf .git

References

« Previous Page Next Page »