1

Let's say I have two tables:

Family [idFamily, idPerson] and
Person [idPerson, hasFamily]

How can I put the first 5 people from Person who has hasFamily='no' into Family with idFamily=1? I've already figured out that I can use:

select * from Person where hasFamily = 'no' limit 5    

But I'm unsure about the insert part.

(I've already asked this before on http://www.reddit.com/r/learnprogramming/comments/2sv1n4/sql_question_about_insert_into/ but the solution did not work)

1 Answer 1

1
insert into family (idFamily, idPerson)
select 1, idPerson 
from Person 
where hasFamily = 'no' 
limit 5  
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.