2

I have a table called "artist" with three columns:

artist_id {PK} | artist_name | artist_url 

There are around 500+ artists in this table.

I want to be able to copy all of the primary keys over to a table called "artist_to_store". This table will have two columns:

artist_id {PK} | store_id. 

Store ID will always be equal to 0

I thought this query would work:

INSERT INTO artist_to_store SET artist_id = (SELECT artistr_id FROM artist) AND store_id = 0 

Instead it reuturns with the error #1242 - Subquery returns more than 1 row.

I know what the error means so nobody needs to explain it. But could somebody please tell me how I get all of the artist_id's from the artist table to the other table?

Thanks, and a Happy New Year when it arrives :)

Peter

2 Answers 2

3

Try this ::

INSERT INTO artist_to_store(artistId, storeId) SELECT artistr_id,0 FROM artist 
Sign up to request clarification or add additional context in comments.

5 Comments

where is the values keyword in insert query?
The author also should know about auto increment locking if uses InnoDB engine.
Igor Timoshenko: I didn't ask about incrementing, I asked about insert data from one table to the next. The increment is set to auto. it will increment in multiples of one. @Sashi Kant, thank you, it works brilliantly. I will bookmrk this page :D :D
@raheelshan: VALUES is not needed when we insert from a select... Peter : you are most welcome
@raheelshan: Thanks Raheel and a Very Happy New year
2
INSERT INTO artist_to_store (SELECT artistr_id,0 FROM artist); 

Try this

4 Comments

will that result, what the OP wants
Ha ha. @SashiKant happy new year buddy :) thanks for guiding :)
It was my pleasure Mate :-)
hmm thanks mate :) but guide me without down voting.. :P Are you from India?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.