Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert multiple rows returned from a subquery

Status
Not open for further replies.

jez

Programmer
Apr 24, 2001
370
VN
Hi Everyone,

I am trying to do this;-
Code:
INSERT INTO RackData (rackNumber) VALUES (SELECT DISTINCT Rack FROM Server);

I am trying to copy all the unique rack numbers from my server table to the new rack table. I could not find info on this on mysql.com and I am currently getting an error about the right syntax to use near 'SELECT.. '.

Is it possible to insert rows like this? I know all the other fields of the new RackData table will be default, but that is not a problem.

Many thanks in advance.

Jez
 
you can have VALUES, or you can have SELECT, but not both

the correct syntax (yes, it's in da manual) is

INSERT INTO RackData (rackNumber)
SELECT DISTINCT Rack FROM Server

:)

r937.com | rudy.ca
 
Thanks very much for this, I am sure it is in the manual, i just couldn't find it ;-)...

Thanks again!

Jez
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top