tags:

views:

127

answers:

6

The database includes a table with a rows: html/css/java/php

How with sql query delete "java"?

The result would be: html/css/php

+3  A: 

See http://www.w3schools.com/sql/sql_delete.asp for details on DELETE.

DELETE FROM TableName WHERE yourColumn = 'java'
aioobe
The question is difficult to understand, but how does this answer address the question at all?? The question says that you start with the row data: `html/css/java/php` and they want to change it to a row with data: `html/css/php`?
KM
I read "rows" in plural, and just assumed that what came after that referred to multiple rows. (Now I see, however, that he has written "a rows" which makes it even less clear!) Anyway, if his intention was to update "html/css/java/php" to "html/css/php" I doubt he would have used the term "delete", but I might of course be wrong.
aioobe
@aioobe, I can see your point now, I guess English is not the OPs native language and such subtle nuances were lost in translation.
KM
A: 

I'm not entirely sure what you're asking, because your question isn't very clear.

If "html", "css", "java", and "php" are different values for the same column, this is what you want:

DELETE FROM table_name WHERE column_name = 'java';

You'll need to replace "table_name" with the name of your table and "column_name" with the name of your column.

Syntactic
A: 

I'm not sure what you want to achieve... If you need to delete column 'java', it should look like

ALTER TABLE table1 DROP COLUMN java
a1ex07
+1  A: 

If there are 4 rows then Aioobe's answer would hold good. If you want to update the column but leave out Java then you should use:

UPDATE table_name SET column_name = Replace(column_name,'java/','')

IF you want to retrieve the information leaving out that data then use:

SELECT Replace(column_name,'java/','') column_name FROM table_name

HTH

Raja
+1... it seems that the user wants to remove a substring. Replacing it with blank should do the trick!
p.campbell
what if the `java` is the last item in the column (no trailing "/")?
KM
@KM- I just answered it to the exact scenario. Your solution would hold good then :-)
Raja
yeah, but the easiest solution for *just* the given case would be `UPDATE YourTable SET YourColumn='html/css/php' WHERE YourColumn='html/css/java/php'` :-)
KM
@KM-lol...awesome. Makes sense. Don't embarrass me man....It was supposed to be a quick solution :-)
Raja
A: 

Here's another guess:

SQL> select * from t23
  2  /

WHATEVER
----------------------------------------------------------------
html/css/java/php

SQL> update t23
  2  set whatever = replace(whatever, '/java', null)
  3  where whatever like '%/java%'
  4  /

1 row updated.

SQL> select * from t23
  2  /

WHATEVER
----------------------------------------------------------------
html/css/php

SQL>

There are other ways to do the same thing. For instance some flavours of database support using RegEx in a similar fashion

APC
+1  A: 

try this (SQL Server syntax, question does not specify which database):

DECLARE @YourTable table (YourColumn varchar(500))
INSERT INTO @YourTable VALUES ('html/css/java/php')
INSERT INTO @YourTable VALUES ('html/css/java')
INSERT INTO @YourTable VALUES ('java/php')
INSERT INTO @YourTable VALUES ('java')
INSERT INTO @YourTable VALUES ('html/css/php')


UPDATE @YourTable
    SET YourColumn=REPLACE(
                               REPLACE(
                                           REPLACE(YourColumn,'/java','')
                                           ,'java/',''
                                      )
                               ,'java',''
                          )

select * from @YourTable

OUTPUT

YourColumn
-------------------
html/css/php
html/css
php

html/css/php

(5 row(s) affected)
KM