This may help you:
mysql create table locais(
- id int,
- type varchar(2),
- `desc` varchar(10));
Query OK, 0 rows affected (0.12 sec)
mysql select * from locais;
+--+--+---+
| id | type | desc |
+--+--+---+
|1 | t1 | sk|
|2 | t2 | dsk |
|
INSERT INTO ztipos (type) VALUES (SELECT DISTINCT type FROM locais)
?
-afan
Miguel Vaz wrote:
Hi,
I have a table LOCAIS with:
idtypedesc
1t1blah blah
2t1uihuih
3t2pokpokp
I want to list only the distinct types and create a
Hi,
I am hoping you meen this:
You have to use the fields in your into -statement and select statement,
not including the field having the auto-numbering
so if e.g. field1 has autonumbering -
insert into table1 (field2, field3) select (field2, field3) from table1;
autonumbering will
That is the effect that I am looking for, but exactly the method that I
am trying to avoid. If I type the column names into my INSERT... SELECT
and someone later adds a column to the table, I would have to go back
into my program and update the statement. I am looking for a way to do
it
Well I haven't realy found a select method in which you can isolate a
field. Like a complementary method, in which you select like one field,
but shows the fields except the field which you have used in your
select-statement.
So you excually want to dynamically insert the records, not knowing
I am using Cold Fusion and as I stated in my original message, if I were
using MySQL 5, then I could use information_schema to retrieve the
column names in the table and do it with variables in Cold Fusion. I do
that on all my pages on the MySQL 5 servers with which I work. However,
the server I
I am not familiour with Cold Fusion but: cant you use 'show columns from
table' ?? and use the result object?
This normally works in e.g. C or PHP
danny
Schimmel LCpl Robert B (GCE 2nd Intel Bn Web Master) wrote:
I am using Cold Fusion and as I stated in my original message, if I were
Relevant bits of the conversation so far, with my thoughts at the end:
Schimmel LCpl Robert B (GCE 2nd Intel Bn Web Master) wrote:
Here is the problem that I am having. I am trying to make a copy of a
full record in a table that has a primary key with auto-increment. The
real problem is that I
Subject: Re: insert into... select... duplicate key
Relevant bits of the conversation so far, with my thoughts at the end:
Schimmel LCpl Robert B (GCE 2nd Intel Bn Web Master) wrote:
Here is the problem that I am having. I am trying to make a copy of a
full record in a table that has a primary key
Ricardo Lopes [EMAIL PROTECTED] wrote:
I have to copy some records from one table into the same table is it
posible?
my sql is like this:
INSERT INTO equipamento_componentes (cod_equipamento_componentes, cod_tipo,
numero, data_colocacao, cod_componente)
SELECT '', 'C', 65, NOW(),
OK, I found the answer.
CREATE TABLE ProductSums
SELECT DISTINCTROW IndenturedList.NSIPartNumber,
Sum(tblInvTransaction.Qty) AS SumOfQty
FROM IndenturedList;
http://www.mysql.com/doc/en/INSERT_SELECT.html
You cannot select from the table you are inserting into. Insert into a temp
table and then insert into holds from that table.
-Original Message-
From: Eric [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 21, 2002 1:14 PM
To: [EMAIL
Hi Eric,
thats oracle function INSERT INTO ... SELECT. it doesn't work in
mysql.
Mirza
[EMAIL PROTECTED]
__
21.11.2002 22:13
Hi,
This should work, I think, but doesn't
INSERT INTO holds (ord_num)
SELECT orders.ord_num FROM orders
Hi,
Yes it works, but you can't insert and select data from the same table with
this syntax.
Regards,
Jocelyn
- Original Message -
From: Mirza Muharemagic [EMAIL PROTECTED]
To: Eric [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Friday, November 22, 2002 12:30 AM
Subject: Re: INSERT
Well, amazingly enough, it works great! I found a test box to try it on
first before implementing this on the production box. This will
definitely make life easier...
On Thu, 2002-11-14 at 10:14, gerald_clark wrote:
Did you try it?
Did it work?
Greg Macek wrote:
Hello,
I recently
Hey Greg:
A slightly easier way to do this is to use a timestamp field. Timestamp is
just a standard mysql data type. When a record is added, it records the
current time. When a record is updated, the timestamp field will be set to
the time of the update.
Thanks for the tip! Looks like I can change my date_archived field to
timestamp(8), since all I care about for this is the date information
(actual time is useless to me). My sql query all of a sudden got a lot
simpler. Thanks again for the help!
On Thu, 2002-11-14 at 11:07, Matthew Baranowski
At 11:15 -0600 11/14/02, Greg Macek wrote:
Thanks for the tip! Looks like I can change my date_archived field to
timestamp(8), since all I care about for this is the date information
(actual time is useless to me). My sql query all of a sudden got a lot
simpler. Thanks again for the help!
This was resolved by adding an auto-increment column.
MySQL does not seem capable of coping with the situation below.
- Original Message -
From: Dave [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Tuesday, April 30, 2002 5:36 PM
Subject: INSERT INTO . SELECT
I am having problems
What analysis are you performing which causes you to conclude that nothing
is being delayed? I'd probably check this by creating an insert...select
which takes at least a few seconds to execute, and then have my test
application log the time, make the call to MySQL, and log the time again. I
- Original Message -
From: David McInnis [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Saturday, March 16, 2002 3:26 PM
Subject: Insert from select
I think that I saw a similar query last week some time but I cannot
remember the sql syntax. Is it possible to insert from a select.
On Saturday, 16. March 2002 09:26, David McInnis wrote:
I think that I saw a similar query last week some time but I cannot
remember the sql syntax. Is it possible to insert from a select.
See http://www.mysql.com/doc/I/N/INSERT_SELECT.html
Regards Georg
Hi
No you can't.
if you are using and AUTO_INCREMENT field as a key you could follow the
INSERT with a select statement like:
SELECT * FROM tablename WHERE keyfield = LAST_INSERT_ID()
See the manual: LAST_INSERT_ID()
-Ursprüngliche Nachricht-
Von: Rick Emery [mailto:[EMAIL PROTECTED]]
Gesendet: Mittwoch, 14. November 2001 19:46
An: Votteler Marc; [EMAIL PROTECTED]
Betreff: RE: INSERT with SELECT on same table
If one of the table's fields is defined as UNIQUE or PRIMARY KEY, it will
allow the insertion
, November 15, 2001 3:30 AM
To: Rick Emery; [EMAIL PROTECTED]
Subject: RE: INSERT with SELECT on same table
Thanks for the response,
you are right I would get an Exception describing that the record
already exists, but because I do not know which DBMS is being used
(one of Oracle, MS SQL
insert-select on the same table is not allowed in MySQL. If I remember
right it isn't allowed in ANSI SQL either, supposedly because it
could lead
to infinite loops if implemented poorly.
Jon Gardiner.
Core SQL support does not require the DBMS to support it; enhanced
SQL support allows
If one of the table's fields is defined as UNIQUE or PRIMARY KEY, it will
allow the insertion only once with that key. When a second attempt is made
to insert the record with the same key, the insertion will be ignored and
you may ignore the error code that results.
Would that work for you?
At 12:53 PM +0800 10/3/01, chong wee siong wrote:
Hi DBAs:
I want to copy TableA in DatabaseA to TableB in DatabaseB
with changes in the attributes of the tables, what options do I have?
I tried these:
a) insert into TableB (id) select (id) from DatabaseA.TableA;
this works
b) insert into
28 matches
Mail list logo