|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Addict
![]() ![]() ![]() Join Date: Jun 2007
Posts: 266
|
is it necessary to use LIMIT 1?
Hi,
Suppose I have the following query: MySQL Code:
here the `user_name` field is primary key as well. In the above, the user somename is retrieved through php. Anyway, my question is, if I know that there will only be one user of the same name - is it requrred to use LIMIT 1? MySQL Code:
My brother says it's more efficient to do so, but I read somewhere that it may slow things down. But since it's just LIMIT 1 there shouldn't be much issue with speed. But I want to know what's the best practice. Thanks ![]() |
|
|
|
|
|
#2 |
|
SQL Consultant
![]() ![]() ![]() Join Date: Jul 2002
Location: Toronto, Canada
Posts: 31,026
|
LIMIT 1 is ~not~ required if your WHERE clause guarantees only one row
best practice would be to leave it out LIMIT is mysql syntax, and will not work if you ever have to port your code to a different database |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 22:53.












Linear Mode
