Hi, could someone help me with this problem:
I have a table
Id status
1 60
1 70
1 90
2 30
2 60
2 80
3 40
3 40
3 60
3 70
4 60
I need to select all Id with status 30,40,50,60,70,80. If any ID do not contain one of these status, do not select these ID even if one or more already met the condition.
In this case, my result would be:
ID
2
3
4
ID=1 is not select because one of them contain status=90
I believe this query work,but very slow.
select distinct Id
from table
where Id not in
(
select ID
from table
where status not in (30,40,50,60,70,80)
)
I have over 30 millions records to search and have to join with other tables.
I have a table
Id status
1 60
1 70
1 90
2 30
2 60
2 80
3 40
3 40
3 60
3 70
4 60
I need to select all Id with status 30,40,50,60,70,80. If any ID do not contain one of these status, do not select these ID even if one or more already met the condition.
In this case, my result would be:
ID
2
3
4
ID=1 is not select because one of them contain status=90
I believe this query work,but very slow.
select distinct Id
from table
where Id not in
(
select ID
from table
where status not in (30,40,50,60,70,80)
)
I have over 30 millions records to search and have to join with other tables.