From: Dan Nelson Date: June 8 2002 4:21am Subject: Re: inserting values w/ relationships List-Archive: http://lists.mysql.com/mysql/111380 Message-Id: <20020608042149.GC71193@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii In the last episode (Jun 07), Jule Slootbeek said: > Hey gang, > I have two tables: > > user > +------------+------------------+------+-----+---------+---------------+ > | Field | Type | Null | Key | Default | Extra | > +------------+------------------+------+-----+---------+---------------+ > | user_id | int(10) unsigned | | PRI | NULL | auto_increment| > | first_name | varchar(10) | | | | | > | last_name | varchar(20) | | | | | > | email | varchar(100) | | | | | > | username | varchar(16) | | | | | > | password | varchar(32) | | | | | > +------------+------------------+------+-----+---------+---------------+ > > and > > quiz > +---------+------------------+------+-----+---------+----------------+ > | Field | Type | Null | Key | Default | Extra | > +---------+------------------+------+-----+---------+----------------+ > | quiz_id | int(10) unsigned | | PRI | NULL | auto_increment | > | user_id | int(10) unsigned | | | 0 | | > | title | varchar(255) | | | | | > +---------+------------------+------+-----+---------+----------------+ > > now user_id and is a relationship between user and quiz... > How do i make sure that when i insert a new row into quiz that user_id > gets taken from quiz, without me having to look it up in user and > entering it manually? > any ideas? INSERT INTO users VALUES (NULL,'myfname','mylname','myemail','username','pass'); INSERT INTO quiz VALUES (NULL,LAST_INSERT_ID(), 'title goes here'); -- Dan Nelson dnelson@stripped $#$@! list filter. sql, query. there. happy?