473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Adding data to row without replacing existing data.

bugboy
160 100+
Am i able to an INSERT into a row that adds to and doesn't replace the current data?

I know i can SELECT the data and concat it with the new data in PHP then INSERT it but i was wondering if i can do it with SQL only? I haven't been able to find anything on it...

Thanks
Nov 17 '07 #1
8 12600
bugboy
160 100+
well duh.. i've realized i should be using UPDATE.. but still don't know how to add to existing row and not replace it.
Nov 17 '07 #2
dinox
3
well i don't quite understand what do you mean by adding without rewriting but i guess you mean something you can use in mysql alone as shortcut ...

for example for incrementing numbers columns...try..
Expand|Select|Wrap|Line Numbers
  1. UPDATE table SET column = column + 1 .. etc
Nov 17 '07 #3
bartonc
6,596 Expert 4TB
well duh.. i've realized i should be using UPDATE.. but still don't know how to add to existing row and not replace it.
That's where unique IDs and the WHERE clause come in. For example:
Expand|Select|Wrap|Line Numbers
  1. UPDATE hetap_data.agencies SET agencyName='In House' WHERE agencyID = 4;
works on a table that looks like this:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE  `hetap_data`.`agencies` (
  2.   `agencyID` integer unsigned NOT NULL auto_increment,
  3.   `stateID` integer unsigned NOT NULL default '0',
  4.   `agencyName` varchar(45) NOT NULL default '',
  5.   PRIMARY KEY  (`agencyID`)
  6. ) ENGINE=InnoDB;
Nov 17 '07 #4
mwasif
802 Expert 512MB
You can concatenate the value in MySQL too, you don't need to process data in PHP (or in client side code).

I assume you have a column in a row with value 'Agree' and want to update it to 'Not Agree'. The following query will change the value from 'Agree' to 'Not Agree' i.e.
Expand|Select|Wrap|Line Numbers
  1. UPDATE table SET
  2. opinion = CONCAT( 'Not ', opinion)
  3. WHERE id=1
Now the column will have the value 'Not Agree'.

And if you want to append the new value at the end, change the parameters order in the CONCAT() function.
Expand|Select|Wrap|Line Numbers
  1. UPDATE table SET
  2. opinion = CONCAT( opinion, ' Not')
  3. WHERE id=1
Are you looking for this?

Checkout MySQL manual to know more about UPDATE statement.
Nov 18 '07 #5
bugboy
160 100+
Yes mwasif, CONCAT is what i was looking for, thanks! And for the other replies as well, all very useful! i love the scripts!

bartonc: What have you done with the table name.. it looks like you have concatenated two tables?
'hetap_data'.'agencies'
...or is this just a normal table name with a period in it?
Nov 18 '07 #6
mwasif
802 Expert 512MB
bartonc: What have you done with the table name.. it looks like you have concatenated two tables? ...or is this just a normal table name with a period in it?
hetap_data is a database name in which the table agencies exists. You can use multiple tables from multiple database in a single query. But for this you have to mention database names with table names as bartonc did.
Nov 18 '07 #7
bugboy
160 100+
ah of course, Thanks guys!
Nov 20 '07 #8
mwasif
802 Expert 512MB
You are welcome, glad to help you.
Nov 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Aladdin | last post by:
I am using the java.util.zip package to create zip files. I can create a new archive and add files to it without any trouble. But if I already have a zip file created, how do I add a new file to...
5
by: Paul | last post by:
Hi I have a table that currently has 466 columns and about 700,000 records. Adding a new DEFAULT column to this table takes a long time. It it a lot faster to recreate the table with the new...
8
by: Kevin Little | last post by:
#!/usr/bin/env python ''' I want to dynamically add or replace bound methods in a class. I want the modifications to be immediately effective across all instances, whether created before or...
2
by: jimmyfishbean | last post by:
Hi, I am using VB6, SAX (implementing IVBSAXContentHandler). I need to extract binary encoded data (images) from large XML files and decode this data and generate the appropriate images onto...
3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
3
by: GL | last post by:
Hi, Is there a way to add a field to an existing table using a query of some sort (without needing to manually add a field to the table). I know how to do it with a make table query, but I have...
3
by: moskie | last post by:
Is there a way to run an alter table statement that adds a constraint for a foreign key, but does *not* check the existing data for refrential integrity? I'm essentially looking for the equivalent...
0
by: AboutJAV | last post by:
I created a crystal report with the report.rpt reportdata.xsd I created the a new dataset with the reportdata myreportdata = new reportdata(); That automatically created a new dataset...
1
by: Allen | last post by:
I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. Using 'new' module or such code as 'def addfunc(...): def helper(...) .. setattr(...)'...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.