harsimranb
harsimranb

Reputation: 2283

get rows that were excluded by sql query

Is there any fast way to get rows that are excluded by a query. For instance I run:

select * from tblUsers where user_type = 3

I'm looking for a fast to get the rows that were excluded by this query.

I understand I can easily change the where clause, but some queries are very complex and take some time to change. With lots of large queries, this task can take very long to do by hand.

Upvotes: 1

Views: 152

Answers (3)

Pinch
Pinch

Reputation: 4207

Dump the results of your super complex query into a temporary table.

ex.

create table #Temp
(
First varchar(50),
Last varchar(50)
)
go
select * from #Temp

then do a join off the original data to get what you are looking for.

Upvotes: 1

Olesya Razuvayevskaya
Olesya Razuvayevskaya

Reputation: 1168

select * from tblUsers 

EXCEPT

select * from tblUsers where user_type = 3

Upvotes: 0

Eric Hauenstein
Eric Hauenstein

Reputation: 2565

For an actual exclusion, you could do:

select * from tblUsers

EXCEPT

select * from tblUsers where user_type = 3

But why not just do

select * from tblUsers where user_type <> 3

Upvotes: 0

Related Questions