Retrieving rows that have 2 columns matching and 1 different

Below is my table called 'datapoints'. I am trying to retrieve instances where there are different instances of 'sensorValue' for the same 'timeOfReading' and 'sensorNumber'.

For example:

 sensorNumber sensorValue timeOfReading

      5            5           6
      5            5           6
      5            6           10   <----same time/sensor diff value!
      5            7           10   <----same time/sensor diff value!

Should output: sensorNumber:5, timeOfReading: 10 as a result.

datapoints table

I understand this is a duplicate question, in fact I have one of the links provided below for references - however none of the solutions are working as my query simply never ends.

Below is my SQL code:

SELECT table1.sensorNumber, table1.timeOfReading
FROM datapoints table1
WHERE (SELECT COUNT(*)
        FROM datapoints table2
        WHERE table1.sensorNumber = table2.sensorNumber
        AND table1.timeOfReading = table1.timeOfReading 
        AND table1.sensorValue != table2.sensorValue) > 1
        AND table1.timeOfReading < 20;

Notice I have placed a bound for timeOfReading as low as 20. I also tried setting a bound for both table1 and table 2 as well but the query just runs until timeout without displaying results no matter what I put...

The database contains about 700mb of data, so I do not think I can just run this on the entire DB in a reasonable amount of time, I am wondering if this is the culprit?

If so how could I properly limit my query to run a search efficiently? If not what am doing wrong that this is not working?

Select rows having 2 columns equal value

EDIT: Error Code: 2013. Lost connection to MySQL server during query 600.000 sec

When I try to run the query again I get this error unless I restart Error Code: 2006. MySQL server has gone away 0.000 sec


Click here view more answers http://ift.tt/1JfjeeR