Link to home
Start Free TrialLog in
Avatar of hefterr
hefterrFlag for United States of America

asked on

T-SQL Exclusion Question

Hi,
 have an idea on this but I am not sure.

I have a table with a 2 column key
ImageTable

KEY:
-  ArticleID integer
-  ImageName  varchar(50)


Data1 varchar(50)
Data2 varachar(50)
etc

I want an SQL (SQL Server 2005) that will select all rows of the table except for 1 row where
ArticleID = 38
ImageName = 'my image'

I have an idea but wanted to see what someone else came up with.

Thanks in advance,
hefterr
Avatar of binaryevo
binaryevo
Flag of United States of America image

Is this what you want?  Thats what i understood from your question.

Select * from Articles where ArticleID <> 38 AND ImageName <> 'my image'

Open in new window


Hope this helps
SELECT * FROM ImageTable
WHERE ArticleID <> 38 AND ImageName <> 'my image'
ASKER CERTIFIED SOLUTION
Avatar of Andrew Crofts
Andrew Crofts
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jim Horn
The above experts are correct.  Quick question though:

>except for 1 row where
Does the '1 row' have any significance, as in are there multiple rows with 38 and 'my image' but the requirement is to delete only one?
Avatar of hefterr

ASKER

To all,
I think you solutions will not also select the following rows:

ArticleID 38
Image Name = 'image1'

ArticleID = 38
ImageName = 'image2'

etc.   Right?
Mine and binaryevo's solutions are incorrect for that reason. andycrofts solution is the best one to do what you're looking for. It will filter out ONLY the row where ID = 38 and ImageName = 'my image'
Avatar of hefterr

ASKER

I also think andycrofys is the correct solution. I'll try it out.

Not sure which is better, but I think I just read :

Select * from ImageTable
Except
Select * from ImageTable where ArticleID = 38 AND ImageName = 'my image'

Thoughts?
Avatar of hefterr

ASKER

Thanks.  Didn't no about the "NOT".

I think my "EXCEPT" would also work?