MySQL select rows according to field length

Hi guys,

I have some domain names stored in a database and I am trying to find domains which are only 3 characters in length.

I could use the MySQL function length(), but this would not return the required results as it would take into account the full length of the domain including extension (.com, .co.uk etc…).

Is there a way I can get 3 character domains from the database like so:

abc.com (would be returned)
def.com (would be returned)
ghi.com (would be returned)

jklm.com (would not be returned as it’s 4 characters in length)

Thanks in advance.

SELECT
  domain
FROM
  table
WHERE
  LENGTH(SUBSTRING_INDEX(domain, '.', 1)) = 3

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html

Thank you Dan, that worked great!