php - Using indexes correctly in SQL query


I'm kind of new to using SQL and I am trying to run a query comparing two values in two separate tables. I have indexed the columns that are being used, but I am not entirely sure how indexing works. I am embedding it in PHP and it currently is taking a long time (sometimes even timing out) when I try to run the query. The two tables have about 250k rows in each so it shouldn't be too big of a query. Here is my code:

$users1 = mysql_num_rows(mysql_query("SELECT DISTINCT idtracker.uuid
  FROM idtracker, download_tracker 
  WHERE idtracker.uuid = download_tracker.pluginId
  && > (NOW() - (2000000))", $con));

I am not sure if it is very efficient comparing two rows directly like I am doing here. If I could just get some insight on what I could do to improve the speed of this query it would be very helpful.

Thanks -Ryan




Before you can do any real testing / optimizing, you need to fix the query: > (NOW() - (2000000))

is wrong.

If is of typeDATE orDATETIME and you want to compare it to another date (NOW() minus something), you need to use the mysql function or something similar.

People are also looking for solutions to the problem: html - How to properly implement a structured menu in php


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.