Saturday, October 25, 2008

I like, like

Let’s say you have a database with over 100,000 records. And you want to pull up one particular record. Going through them one by one would not be good for your mental health. The easiest approach would be to search by primary key. But suppose the primary key is made up of 25 digits. Do you really want to type in that many numbers when writing your search query? Most likely not.

When I faced this situation I spent a lot time typing in numbers. With deadlines looming I found that this approach was not practical. That’s when I came across the “like” command. It let me search by only a portion of the primary key. Which means I only had to remember the first few digits of the key to get me going. Which was very convenient. (I am sure there are hard core DBAs out there who have better ways of doing this, do share)

That also raises the question of how people deal with pressure. Some would give up, which is a real shame. Others would keep at it and try to make it. This is when the pressure turns out to be good for you as it makes you better. It’s the old adage of the diamond in the rough.

2 comments:

vince said...

Actually LIKE and NOT LIKE are excellent ways to do what you were trying to do. They aren't as fast as a normal query search, as they can't take advantage of indexes. The only drawback (which in some cases can be an advantage) is that they aren't case sensitive.

If you're looking for a name and know how it's pronounced, but not how it's spelled, you can use SOUNDS LIKE. It works best with English words, with other languages, your mileage may vary.

Oh, I'm assuming you're searching a mySQL database.

Anonymous said...

Yes indeed i am. I'll look into indexes. That's also a good way to speed things up.