MySQL Forums
Forum List  »  Newbie

Re: INSERT ... SELECT ... AND
Posted by: Felix Geerinckx
Date: June 23, 2005 06:27AM

Christos Br�unle wrote:

> i try to do a subquery on INSERT ... SELECT
> i need the id of two entrys from one table and want to insert them into a nother table. also i
> want to insert a value to the same table.

USE test;
DROP TABLE IF EXISTS lemma;
CREATE TABLE lemma (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
lemma VARCHAR(25)
);

INSERT INTO lemma (lemma) VALUES
('my'), ('question'), ('your'), ('answer');

DROP TABLE IF EXISTS a;
CREATE TABLE a (
id1 INT NOT NULL,
id2 INT NOT NULL,
c INT NOT NULL
);

INSERT INTO a
SELECT
lem1.id, lem2.id, 4
FROM lemma lem1, lemma lem2
WHERE
lem1.lemma = 'my'
AND lem2.lemma = 'question';

SELECT * FROM a;

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
Re: INSERT ... SELECT ... AND
June 23, 2005 06:27AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.