Solved

T-SQL Exclusion Question

Posted on 2013-01-25
9
231 Views
Last Modified: 2013-01-26
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
0
Comment
Question by:hefterr
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:binaryevo
ID: 38818627
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
0
 
LVL 11

Expert Comment

by:Simone B
ID: 38818628
SELECT * FROM ImageTable
WHERE ArticleID <> 38 AND ImageName <> 'my image'
0
 
LVL 13

Accepted Solution

by:
Philip Pinnell earned 500 total points
ID: 38818640
SELECT * FROM ImageTable
WHERE Not (ArticleID = 38 AND ImageName = 'my image' )
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38818649
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?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 1

Author Comment

by:hefterr
ID: 38818672
To all,
I think you solutions will not also select the following rows:

ArticleID 38
Image Name = 'image1'

ArticleID = 38
ImageName = 'image2'

etc.   Right?
0
 
LVL 11

Expert Comment

by:Simone B
ID: 38818710
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'
0
 
LVL 1

Author Comment

by:hefterr
ID: 38818744
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?
0
 
LVL 1

Author Closing Comment

by:hefterr
ID: 38819393
Thanks.  Didn't no about the "NOT".

I think my "EXCEPT" would also work?
0
 
LVL 13

Expert Comment

by:Philip Pinnell
ID: 38822705
thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now