hefterr
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
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
SELECT * FROM ImageTable
WHERE ArticleID <> 38 AND ImageName <> 'my image'
WHERE ArticleID <> 38 AND ImageName <> 'my image'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
>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?
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?
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'
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?
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?
ASKER
Thanks. Didn't no about the "NOT".
I think my "EXCEPT" would also work?
I think my "EXCEPT" would also work?
thanks
Open in new window
Hope this helps