what you provided would almost do it... but i want to insert into the "dog
table" the name that i submit...

i'd like to do something like....

if i submit dogname, ownername

insert into dog (name, ownerid) values ($dogname, owner.id)
select ownerid from owner where owner.name = $ownername;

-bruce



-----Original Message-----
From: Emmett Bishop [mailto:[EMAIL PROTECTED]
Sent: Sunday, July 04, 2004 12:59 PM
To: [EMAIL PROTECTED]
Subject: Re: mysql sql question


Bruce,

what you want it the insert into ... select statement.

It's like this:

insert into dog (name, ownerid)
select name, ownerid from owner where ownerid = 8;

Does that sound like what you need?

-- Tripp



--- bruce <[EMAIL PROTECTED]> wrote:
> hi...
>
> i have two hypothetical tables
> create table owner (
>     -> name char(20) ,
>     -> ownerid int(10) auto_increment primary key);
>
> create table dog (
>     -> name char(20) ,
>     -> ownerid int(10),
>     -> dogid int(10) auto_increment primary key);
>
> i'm curious as to how i'd go about inserting a name
> and the id of the owner,
> in table "dog", in a single sql statement.
>
> something like this psuedo sql..
>  insert table (name, ownerid) values ($name,
> $ownerid)
>    where owner.owner = owner
>
> in other words, an app would supply the values for
> the "dog name", and the
> "owner". the sql would be able to derive the
> "ownerid" for the "owner" from
> the owner table, and then be able to insert the
> "ownerid", and "dogname"
> into the dog table...
>
> searching through google gets me to being able to
> write a php/perl script
> where i can do this using multiple sql statements..
> but i'm trying to see
> how to do it in a single statement...
>
> any comments/criticisms would be helpful...
>
> thanks...
>
> -bruce
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
>
http://lists.mysql.com/[EMAIL PROTECTED]
>
>





__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - 100MB free storage!
http://promotions.yahoo.com/new_mail


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to