Solved

T-SQL Exclusion Question

Posted on 2013-01-25
9
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 66

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
 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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