0

What is the best choice to get result from database? (in server side DAO)

  1. Using query syntax (like JOIN, WHERE)

  2. Using programming business logic

    • ex)
      1. Get data using simple query (SELECT userId FROM customer)
      2. use Programming Code (User user = query.result)
      3. execute another query using code variable value {query.execute("SELECT * FROM order WHERE userid = ?",[user.id])}
WooHee
  • 1
  • In most cases you would go with a JOIN, Rule-of-thumb: Database queries inside loops are seldom a good idea. – CBroe Oct 18 '17 at 09:20
  • Databases are designed to do this. Why would you possibly want to fetch every result, and then per record you find, execute another query? (Let's say you have 1000 users, that means 1001 queries instead of 1. Which do you think performs better?) – Ivar Oct 18 '17 at 09:21
  • Possible duplicates: - [Using an ORM or plain SQL?](https://stackoverflow.com/questions/494816/using-an-orm-or-plain-sql) - [Are there good reasons not to use an ORM?](https://stackoverflow.com/questions/194147/are-there-good-reasons-not-to-use-an-orm) - [Raw SQL vs OOP based queries (ORM)?](https://stackoverflow.com/questions/5834540/raw-sql-vs-oop-based-queries-orm) – wast Oct 18 '17 at 09:27
  • Possible duplicate of [Using an ORM or plain SQL?](https://stackoverflow.com/questions/494816/using-an-orm-or-plain-sql) – wast Oct 18 '17 at 09:27
  • @wast I don't see what this question has to do with ORM? – Ivar Oct 18 '17 at 09:31
  • @Ivar I think he thought of ORM on 2. so he is asking what is the best practice. – wast Oct 18 '17 at 09:32
  • He is talking about server side DAO so I doubt he actually thinks of using an ORM. His steps also don't really point in that direction. – Ivar Oct 18 '17 at 09:49

0 Answers0