I have 2 tables Project and ProjectList like this
Project
ProjectID
Name
ProjectListID - allow null
In ProjectList
ProjectListID
ProjName
Now what i need here, i want only those recoed from ProjectList table which ProjectListID not in Project table.
I made a query but it is taking lot of time to execute.
select * FROM projectslist pl where pl.ProjectsListID not in (SELECT p.ProjectsListID FROM project p where (p.ProjectsListID is not null and p.ProjectsListID <>0))
Please help me to create optimize query. I am using My SQL.
NOT NULLcondition in your query is redundant:<> 0implies it:For this to work fast, you need to create an index on
project (ProjectsListID).Could you please run
and post its output here?
Update:
Since the column in question is nullable, it is better to rewrite the query as
NOT EXISTS: