1

I have working on two way to fetch datas from multiple tables.

  1. MYSQL JOIN query
  2. PHP foreach loop query

Can you provide the idea of which one work faster?

Thanks in Advance.

3
  • 2
    Possible duplicate of MySQL query in a loop vs using a SQL join Commented Jul 17, 2018 at 10:00
  • 2
    If you have been working on it, then show us! Commented Jul 17, 2018 at 10:00
  • 1
    1/ We have no idea how your data looks like, 2/ We have no idea how many data you have, 3/ Can you please show us an example of what you tried? The best way is to test it yourself so you will have an idea of what's faster ! But the less you send request to your database, the better it is I think. Send ONE query with some join is better than sending thousand of query in a foreach loop Commented Jul 17, 2018 at 10:01

1 Answer 1

3

If SQL can do the task, it can usually do it faster. Reasons:

  • Not shoveling data between client (PHP) and server (mysqld).
  • Not having to parse and optimize multiple queries.
  • More optimization tricks that you might not think of. (The flip of this is that you might not have the best indexes, etc on the queries.)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.