PDA

View Full Version : Joining two columns (fields) ?


student101
07-27-2008, 02:07 PM
How do I join two columns (fields) in one db table ? - (wish there was a drag & drop function)

Two columns (fields)
usr_name => name
usr_surname => surname
Would like to join them;
name surname in one table called usr_name
Is there a join or merge query that can do this like;
merge usr_name," ",usr_surname into usr_name
Cheers

davidj
07-27-2008, 02:58 PM
if they ar being stored in the db there is no need to do this from there

just do this in php when you need to display them together

student101
07-27-2008, 05:02 PM
I got no problems displaying them if or when needed, I really want to merge the columns into one, unable to find a resource that is able to assist on this.

student101
07-27-2008, 05:35 PM
Hope that I made sense in the first post?

Do I need to do;

ALTER TABLE table_name
ADD column_name datatype
Insert into column_name from other column
DROP COLUMN column_name

student101
07-27-2008, 07:37 PM
This worked.
update tbl_login set usr_name = concat(usr_name,' ',usr_surname)


Thanks

Cheers

davidj
07-27-2008, 08:12 PM
why cant you merge them when they are inserted using the first db call

student101
07-27-2008, 08:53 PM
why cant you merge them when they are inserted using the first db call
Not sure what you mean?

Oh I see what you mean, no they aren't inserted - they already exist in the DB, I wanted them merged into one column.

davidj
07-27-2008, 10:01 PM
OK

so you want them merged after they have been inserted separately

or you want to change the seperated values currently held into a single one and then store the single column from now on?

or are you holding a single concatinated column as well as the two seperate ones

student101
07-27-2008, 10:06 PM
OK
or you want to change the seperated values currently held into a single one and then store the single column from now on?
That's it, only one column needed - did a full re-design on the DB was 15 columns now only 10 columns - it may even get smaller, not finished yet.

davidj
07-27-2008, 10:08 PM
ahh right

so that update using concat was just one off procedure to reduce your table