Solved

T-SQL Exclusion Question

Posted on 2013-01-25
9
233 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
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…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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