5

Do I need to write LIMIT 1 using PDO's fetch() method? This assumes that I need only one result. I'm wondering, does using LIMIT 1 will help to save resources and loading time?

Gajus
  • 69,002
  • 70
  • 275
  • 438

1 Answers1

1

The LIMIT clause is just one more SQL feature you can use to retrieve the information you need. Asking whether you need LIMIT cannot be answered unless you narrow your context. It's like asking if you need WHERE or JOIN. It depends on your data and your needs.

Not sure if that's what you have in mind, but I've seen projects where the developer was not fluent in SQL and just did the heavy lifting in application code, typically restricting their SQL to SELECT * FROM table. I think it's worthwhile to learn the basics of SQL so you're able to return the exact rows and columns you need. That's often a great boost for performance.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360