1

I have a table in my database called Games. This table has a column called "players_attending" that stores varchars. I need to be able to add a new string into this column while still saving the previous strings.

For example, if one row of Games had players_attending = "bryan." I want to be able to add "matt" to players_attending but also still have bryan.

The result should be players_attending = "bryan matt."

Is this possible?

2
  • SQL uses || to concatenate strings: players_attending = players_attending || 'matt' Commented Dec 7, 2015 at 7:11
  • 2
    which RDBMS you used? Commented Dec 7, 2015 at 7:13

4 Answers 4

0

Your query would be like:

Oracle:

Update table set field =  field || ' matt'

MySQL:

Update table SET col=CONCAT(col,' matt');

MSSQL:

Update table set col = col + ' matt'
Sign up to request clarification or add additional context in comments.

1 Comment

The first statement is not specific to Oracle. This is how string concatenation is defined in the SQL standard. And Postgres, DB2, Firebird, Ingres, Informix and many other DBMS comply with that standard (I think only MySQL and SQL Server chose to ignore that)
0

Yes, you would concatenate the string using ||

update Games 
   set players_attending = players_attending || ' ' || new_player_name 
   where Id = x

4 Comments

I tried that, by doing, UPDATE Games SET players_attending = players_attending ||'bryan625' WHERE location = 'Lady Bug Park' AND id = 1; and it just sets the value of players_attending to 0...
FYI I am using phpMyAdmin
What RDBMS are you using (Oracle, SQL server, MySQL, etc)
@BryanPenaloza: In a default installation, MySQL uses || for something different. You should enable PIPES_AS_CONCAT in your installation to be more standard compliant.
0

use concatenation to add two string and the where clause to get the required data records

update table GAMES set field = field || ' ' || 'Matt' where field = 'bryan'

Comments

0

You can update the column by concatenating value to it. SQL Server example

UPDATE YourTable
SET field = CAST(field AS VARCHAR(50)) + CAST('matt' AS VARCHAR(50))
WHERE (condition)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.