Re: INSERT ... SELECT ... AND
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.