As the subject says, ... what is the best way to retrieve only one record?
I mean, let's suppose that I need to get certain record given its ID, so I *know* that there will be only one.
I'm using LIMIT 1, but I wanted to know if there is some other advice that should be taken into account...
select only one record
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
For optimizing queries the general rules are
- avoid unnecessary column selection
- make joins as restrictive as possible to weed out stuff you don't want as early as possible
- correctly use indexes
- correctly select storage engines
- correctly choose column types
- use EXPLAIN to examine how the database understands and implements your queries
- read the documentation of your database thoroughly. They often have sections on query optimization. They aren't written to suck up space; read them.