Hi guys, I really need some help. I have two tables tbl_question with 2 columns question_id , question_name and tbl_answers with 3 columns answer_id,answer_name and questionFK. I want to get values from question_id and compare them with questionFK if some values are missing in questionFK then I need a insert of missing values. values from questionFK have to be always same as question_id
I'm not sure if you can do this all in one step but what you want is an outer join:
select question_id, question_name from tbl_questions q left outer join tbl_answers a on q.question_id=a.questionFK where a.questionFK IS NULL;
Once you know which questions are unanswered you can insert the rows you need.
insert into tbl_answers (questionFK) SELECT question_id from tbl_questions q left outer join tbl_answers a on q.question_id=a.questionFK where a.questionFK IS NULL;
I'd check the results of the first query before running the second one. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php