MySQL Tips & Tricks

Friday, January 30, 2009

Search for names of a certain length

Suppose if we want to find the names that contain exactly five characters, we use a special character "_"(underscore). The following query will list all the five letter names from the table employees.


select * from employees where firstname like '_____';

Labels:

1 Comments:

  • You could also use:

    select *
    from employees
    where LENGTH(firstname) = 5;

    Which is most inefficient is debatable. ;-)

    By Blogger Lee, At July 23, 2009 11:50 AM  

Post a Comment



<< Home