Bastien Vandamme
Bastien Vandamme

Reputation: 18465

Unique complex SQL request VS several simple SQL request with merging in my code?

Could you help me to understand what is the best solution between unique complex SQL request and several simple SQL request with merging in my code?

On his home page I would like to display the list of new job offer of these 3 area of interst order by date. What should I do in my code.

  1. A unique complex SQL request with join on job offer on competence and area of interest and area of interest of my user and my user table with a WHERE clause on my user

  2. A more simple SQL request that a call 3 times to get 3 list of job offer with join on job offer on competence and area of interest with WHERE clause on my area of interest and after that I merge my three lists in my code.

What if i need to order my list on the job offer date but highlight or prioritize the job offers that may be in several area of interest.

EDIT

I have a database requirement : I need to works with stored procedure only

Upvotes: 0

Views: 70

Answers (1)

Argeman
Argeman

Reputation: 1353

One complex query is just much better in 99% of all cases.

However, if you need to process the data very often and don't need the newest data all the time, you can of course reimplement the database logic in your code and achieve a better performance. But that will only work if you use the data very often, and if you can ignore any changes during that time. And remember, it is quite much work to implement all that join logic with proper indexing and optimization. I would suggest that it's just not worth the effort.

Upvotes: 1

Related Questions