I have a mysql table of data and I only need to return the rows that have no "deactive" status And you do not have a total of 0 (but rows can be where the condition is inactive and total is not 0 and vice versa). Before I needed this requirement, I was just doing a standard query for selecting all the rows:
SELECT * from tableName where UID = ID; However now when I change the query to add the above constraints:
SELECT * from the table name where UID = ID and (position! =) "Inactive" or total! = 0); This is taking too long to complete the query below. Why is this happening and is it a better way to do this inquiry?
The first query based on an index (I'm assuming 'UID'). The second query is filtering on other values. Run it, and it will help you to figure out how best you can optimize it:
Select from a wide range * Where UID = ID and position from the table name! = "Inactive" or Total! = 0; It is dirty, but it will probably be a quick way to speed up:
SELECT * FROM (Select from the name of the table where UID = Id) as temporary WHERE temp.status! = "Deactive" or a temporary total! = 0; Forces the query to obtain the rows for the first time with a UID, and then filter them instead of having to scan a large table. As I said earlier, XLen has extended your friend
Comments
Post a Comment