sql command - copy of one row

sql command - copy of one row

Post by - = k o l i s k o = » Tue, 20 Mar 2001 20:23:51



Hi!

I have a problem. I would like copy one row from table1 to
another table2. How could I do?

I tried something like this:

insert into table2 values (select * from table1 where username = '$uname')

both (table1 and table2) have the same structure.
Every time when I try do this sql command i get syntax error in sql command.

My question:

How could I copy one row from one table to other table?

Thank You for help!

S pozdravem,
Michal Kolesar
+420 608 225025

http://www.egarden.cz
server of free unix services

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

sql command - copy of one row

Post by Peter Pentch » Tue, 20 Mar 2001 20:30:23



Quote:> Hi!

> I have a problem. I would like copy one row from table1 to
> another table2. How could I do?

> I tried something like this:

> insert into table2 values (select * from table1 where username = '$uname')

> both (table1 and table2) have the same structure.
> Every time when I try do this sql command i get syntax error in sql command.

Is there really an SQL server that would accept this query?  Try just:

insert into table2 select * from table1 where username = '$uname';

G'luck,
Peter

--
because I didn't think of a good beginning of it.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

sql command - copy of one row

Post by - = k o l i s k o = » Tue, 20 Mar 2001 20:38:39


Hi!


> > Hi!

> > I have a problem. I would like copy one row from table1 to
> > another table2. How could I do?

> > I tried something like this:

> > insert into table2 values (select * from table1 where username =
'$uname')

> > both (table1 and table2) have the same structure.
> > Every time when I try do this sql command i get syntax error in sql
command.

> Is there really an SQL server that would accept this query?  Try just:

> insert into table2 select * from table1 where username = '$uname';

Yes!

It is working fine!

Thank You very much.

> G'luck,
> Peter

> --
> because I didn't think of a good beginning of it.

> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)


> To unsubscribe, e-mail


Quote:> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

sql command - copy of one row

Post by - = k o l i s k o = » Tue, 20 Mar 2001 20:53:08


Hi!

i try one little question.

when the table2 have one more row then table1.. is possible try something
like this:

insert into table2 ($date, select * from table1 where username = '$uname')

where $date -> system time and date generated from php.

If you understand.. table2 is backup of table1 when is something (row)
changed...
so I would like copy the row from table2 to table2 but try to add a field
named "time" or "date".

Is possible copy it and add in new table a new field?


> > Hi!

> > I have a problem. I would like copy one row from table1 to
> > another table2. How could I do?

> > I tried something like this:

> > insert into table2 values (select * from table1 where username =
'$uname')

> > both (table1 and table2) have the same structure.
> > Every time when I try do this sql command i get syntax error in sql
command.

> Is there really an SQL server that would accept this query?  Try just:

> insert into table2 select * from table1 where username = '$uname';

> G'luck,
> Peter

> --
> because I didn't think of a good beginning of it.

> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)


> To unsubscribe, e-mail


Quote:> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

sql command - copy of one row

Post by Peter Pentch » Tue, 20 Mar 2001 20:57:58



Quote:> Hi!

> i try one little question.

> when the table2 have one more row then table1.. is possible try something
> like this:

> insert into table2 ($date, select * from table1 where username = '$uname')

One more 'column' you mean, not 'row'.  Yes, this is possible, though
a bit more difficult - you cannot use '*' in the select statement, rather
something like this..

If table1 has 3 columns - name, birthdate, salary - then you can do:

INSERT INTO table2 SELECT '$date', name, birthdate, salary FROM table1
        WHERE username='$uname';

You can actually place any constant value in a SELECT statement - that's
the idea behind the above insert-from-select.

G'luck,
Peter

--
If this sentence were in Chinese, it would say something else.

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

sql command - copy of one row

Post by - = k o l i s k o = » Tue, 20 Mar 2001 22:17:08


super!

it work fine.

Thank You!

S pozdravem,
Michal Kolesar
+420 608 225025

http://www.egarden.cz
server of free unix services

----- Original Message -----



Sent: Monday, March 19, 2001 12:56 PM
Subject: Re: sql command - copy of one row


> > Hi!

> > i try one little question.

> > when the table2 have one more row then table1.. is possible try
something
> > like this:

> > insert into table2 ($date, select * from table1 where username =
'$uname')

> One more 'column' you mean, not 'row'.  Yes, this is possible, though
> a bit more difficult - you cannot use '*' in the select statement, rather
> something like this..

> If table1 has 3 columns - name, birthdate, salary - then you can do:

> INSERT INTO table2 SELECT '$date', name, birthdate, salary FROM table1
> WHERE username='$uname';

> You can actually place any constant value in a SELECT statement - that's
> the idea behind the above insert-from-select.

> G'luck,
> Peter

> --
> If this sentence were in Chinese, it would say something else.

> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)


> To unsubscribe, e-mail

> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

 
 
 

1. copying rows from one database to another database

Hi All,

What is the best way to move an entire row of data from a table in one
database to another table in a different database?  The two databases are on
the same system.

Thanks in advance,
Dang H. Nguyen

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)



Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

2. Palm / IrDA /Windows ME

3. remove duplicate rows while keeping one copy

4. Toolbar Button for Superscript

5. copy command permissions problem. only \copy works why

6. RCA DCM235 diagnostics ??

7. A SQL statement to copy a blob from one table to another

8. Test Case Database | Linux

9. Copying data from one SQL database to another using dataset object

10. Problems running multiple commands in one SQL string thru ODBC

11. HowTo store from DataSet to SQL Server Database with one command??

12. First Row from SQL database not showing up with DataReader

13. Making result rows to one row