Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The forum looks great! You guys have done a fantastic job on arranging things there...Your site is very precise and fun to visit..."

Geography

Where in the world do Tek-Tips members come from?

copy row but change one valueHelpful Member! 

dkemas (Programmer)
6 Jun 12 8:27
I need to copy a row in a table but have the id auto increment and also change one of the values in the new row

I am very close, my sql will copy the row and increment the id, but how do I change one of the fields. Here is what I have that will copy the row with id 11, insert a new row with the next available id

CODE

INSERT INTO mytable SELECT 0, `field1`, `field2`, `field3`, `field4`, `field5` FROM mytable WHERE id = 11

Is it possible to modify this to insert the value 'newvalue' into field4 but still copy the rest of the values?

Thanks
feherke (Programmer)
6 Jun 12 8:43
Hi

I am confused. You mean like this ?

CODE --> MySQL

INSERT INTO mytable SELECT 0, `field1`, `field2`, `field3`, 'newvalue', `field5` FROM mytable WHERE id = 11

Feherke.
http://feherke.github.com/

dkemas (Programmer)
6 Jun 12 8:54
Exactly that yes, but I would get the error

#1054 - Unknown column 'newvalue' in 'field list'

if I did that

Helpful Member!  feherke (Programmer)
6 Jun 12 9:00
Hi

Quote (dkemas)

#1054 - Unknown column 'newvalue' in 'field list'
That would mean, you are enclosing newvalue in backtick ( ` ). You have to enclose it in single quotes ( ' ).

Feherke.
http://feherke.github.com/

dkemas (Programmer)
6 Jun 12 9:08
Aha I see, so backtick will insert the value of the field, single quotes will insert my value.

I wondered why phpmyadmin was using backticks after I execute a query.

Thank you Feherke
feherke (Programmer)
6 Jun 12 9:23
Hi

Quote (dkemas)

Aha I see, so backtick will insert the value of the field, single quotes will insert my value.
Yes, you can say so. In other words
[off-topic]
Personally I never understood this habit, popular among MySQL users, of quoting all identifiers. Backticks are required if you use reserved word to name a table, field or other object. For example like in this aberrant example :

CODE --> MySQL

create table `create table` ( `insert` int, `into` int );
[/off-topic]

Feherke.
http://feherke.github.com/

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close