php - mysql select query very slow when using where clause

if ($result = mysqli_query($link, "SELECT * FROM `users`")) {
      while ($row = mysqli_fetch_assoc($result)) {


When I use the above code query works fine..

But when I use the following code mysql is very slow.

if ($result = mysqli_query($link, "SELECT * FROM `users` WHERE name IS NULL")) {
      while ($row = mysqli_fetch_assoc($result)) {


Can someone tell me why and how to make that query faster?




There are many ways to make the query run faster.

  1. Avoid* as it first look for all the column then it gives them out. Solution - Use the attribute name manually such as:

    Select `name`, `age`, `XYZ` from `users` where `name` IS NULL
  2. Use on the query.

  3. Use to find out which index could be used and which index is actually used. Create an appropriate index if necessary.




You need to add an index on thename column to speed things up.

People are also looking for solutions to the problem: Netbeans (PHP): How to disable the imposed multi-lines comment syntax?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.