Insert into sql statement with union query

giedrius

Registered User.
Local time
Today, 20:09
Joined
Dec 14, 2003
Messages
80
Hi,

Does anybody know if it is possible at all to have a UNION SELECT statement within an INSERT INTO statement?

thanks,
giedrius
 
Perhaps a UNION can exist as a sub query but why not just use the UNION query as the FROM in an INSERT query.

Len B
 
Not sure what you mean by "FROM in an INSERT query". Does INSERT have a FROM clause? I use syntax like this:

INSERT INTO clients
(client_id, client_name)
SELECT supplier_id, supplier_name
FROM suppliers
UNION ALL SELECT supplier_id, supplier_name
FROM suppliers2;

and it doesn't seem to work. I therefore started wondering if INSERT accepts union queries in its Select part.

giedrius
 
giedrius said:
INSERT INTO clients
(client_id, client_name)
SELECT supplier_id, supplier_name
FROM suppliers
UNION ALL SELECT supplier_id, supplier_name
FROM suppliers2;

giedrius

Your syntax for sub query is incorrect but try something along the lines of

INSERT INTO clients
(client_id, client_name)
SELECT supplier_id, supplier_name
FROM Union Query Name;


Len B
 
Len,

Your syntax works just fine! Thanks.

giedrius
 

Users who are viewing this thread

Back
Top Bottom