Mr A
Mr A

Reputation: 6768

Help with Select Query in ado.net

I have got a table(newsImages) with columns newsID(Foreign Key) , newsImage , imageID(primary Key), What my query is Select newsImage From newsImages Where newsID = 'something'

The query returns all the images with specific newsID, What I want is to remove a row who has image named"something" from the resultant query. Any help or suggestion will be appreciated

Upvotes: 0

Views: 350

Answers (3)

Chris
Chris

Reputation: 570

SELECT * FROM newsImages WHERE newsImage <> "something" AND newsID = <value>;

Upvotes: 1

Robb
Robb

Reputation: 3851

To select everything but the newsImage with id 'something'

 Select newsImage From newsImages Where newsID <> 'something'

to delete newsImage with ID 'something' from the table newsImages

 delete from newsImages where newsID = 'something'

Upvotes: 1

Mongus Pong
Mongus Pong

Reputation: 11477

You would do

DELETE FROM newsImage
WHERE newsID = 'something'

But be careful, it looks as though your ID field is a text field.

Are you sure that the ID field is guaranteed to be unique? Is it defined as a Primary Key? If not you may have several rows with the same ID and you may delete more than you were expecting to.

EDIT

Ah, ok

SELECT newsImage From newsImages 
Where newsID = 'something'
AND newsName <> 'somethingElse'

Upvotes: 1

Related Questions