Question: Given a table structure like this:

```
CREATE TABLE `user` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `name` varchar(32) NOT NULL,
  `username` varchar(16) NOT NULL,
  `password` char(32) NOT NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `username` (`username`)
);

```

Is there any use in using the LIMIT keyword when searching by username, or is the DB smart enough to know that there can only possibly be one result, and therefore stop searching once it's found one?

```
SELECT * FROM `user` WHERE `username` = 'nick';

-- vs --

SELECT * FROM `user` WHERE `username` = 'nick' LIMIT 1;

```

---

*Update:* Thanks for the answers, they've been enlightening. It seems like, even though it's unnecessary, putting `LIMIT 1` on the query doesn't hurt, and probably increases readability (you don't have to go looking into the DB schema to know that only one is going to be returned). Special shoutout for JR's answer - I didn't even know you could do that with indices.

Also, there's a similar question I've found [here](https://stackoverflow.com/questions/34488/does-limiting-a-query-to-one-record-improve-performance), which might also help.

Answer: 
I've always been told and read that you should include the `LIMIT` everytime you only want 1 result. This just tells the DB that it should stop so matter what. In your case, you're probably right it doesn't make a difference, but I think it's better just to always do than always deciding and leaving it out one time when you need it.
The sql query optimizer should be smart enough to figure this out.