0

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

1
  • i dont want to delete it from database, i want to remove it from displaying in the results Commented May 19, 2011 at 15:11

3 Answers 3

1

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'
Sign up to request clarification or add additional context in comments.

3 Comments

i dont want to delete it from database, i want to remove it from displaying in the results
<> , what does dat stands for
<> means not equal to. (the opposite of =) so this query will not return any rows where newsName equals 'somethingElse'
1

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'

2 Comments

i dont want to delete it from database, i want to remove it from displaying in the results
@Muhammad Awais - I thought that might be the case that's why i wrote the first query which selects everything except the newsImage with ID 'something'
1
SELECT * FROM newsImages WHERE newsImage <> "something" AND newsID = <value>;

2 Comments

i dont want to delete it from database, i want to remove it from displaying in the results
Are you removing rows based on the results?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.