Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Insert query

Hi

I have 3 tables. Table A, B and C.
Table A Table B Table C
UserID UserNo UserID
UserNo Name Name

I need to populate Table C with information from Table B but I need the UserID
for Table C from Table A.
Table A and B are connected by UserNo and into Table C I need to put UserID
(from table A which corresponds to UserNo from Table B)
Hope it makes sense

MY current insert statement goes something like this
INSERT INTO TableC(Name,UserID)
SELECT Name, UserNO
FROM TableB
WHERE UserNo
(SELECT UserID
FROM TableA INNER JOIN
TableB ON TableA.UserNo= TableB.UserNo) as UserNo

I know I'm doing something stupid. Suggestions welcome
[760 byte] By [Nimisha] at [2007-11-9 21:11:19]
# 1 Re: Insert query
Sorted, was stupid as I guessed
Nimisha at 2007-11-11 23:51:17 >
# 2 Re: Insert query
"Nimisha" <nimisha_uk@yahoo.com> wrote:
>
>Hi
>
>I have 3 tables. Table A, B and C.
>Table A Table B Table C
>UserID UserNo UserID
>UserNo Name Name
>
>I need to populate Table C with information from Table B but I need the
UserID
>for Table C from Table A.
>Table A and B are connected by UserNo and into Table C I need to put UserID
>(from table A which corresponds to UserNo from Table B)
>Hope it makes sense
>
>MY current insert statement goes something like this
>INSERT INTO TableC(Name,UserID)
>SELECT Name, UserNO
>FROM TableB
>WHERE UserNo
> (SELECT UserID
> FROM TableA INNER JOIN
> TableB ON TableA.UserNo= TableB.UserNo) as UserNo
>
>I know I'm doing something stupid. Suggestions welcome
>
ML at 2007-11-11 23:52:18 >
# 3 Re: Insert query
"Nimisha" <nimisha_uk@yahoo.com> wrote:
>
>Hi
>
>I have 3 tables. Table A, B and C.
>Table A Table B Table C
>UserID UserNo UserID
>UserNo Name Name
>
>I need to populate Table C with information from Table B but I need the
UserID
>for Table C from Table A.
>Table A and B are connected by UserNo and into Table C I need to put UserID
>(from table A which corresponds to UserNo from Table B)
>Hope it makes sense

just aquick thought
I usually
SELECT Name, UserNO
INSERT INTO TableC(Name,UserID)
FROM TableB
WHERE UserNo
(SELECT UserID as UserNo
FROM TableA INNER JOIN
TableB ON TableA.UserNo= TableB.UserNo)

>
>MY current insert statement goes something like this
>INSERT INTO TableC(Name,UserID)
>SELECT Name, UserNO
>FROM TableB
>WHERE UserNo
> (SELECT UserID
> FROM TableA INNER JOIN
> TableB ON TableA.UserNo= TableB.UserNo) as UserNo
>
>I know I'm doing something stupid. Suggestions welcome
>
ML at 2007-11-11 23:53:17 >
# 4 Re: Insert query
"Nimisha" <nimisha_uk@yahoo.com> wrote:
>
>Hi
>
>I have 3 tables. Table A, B and C.
>Table A Table B Table C
>UserID UserNo UserID
>UserNo Name Name
>
>I need to populate Table C with information from Table B but I need the
UserID
>for Table C from Table A.
>Table A and B are connected by UserNo and into Table C I need to put UserID
>(from table A which corresponds to UserNo from Table B)
>Hope it makes sense
>
>MY current insert statement goes something like this
>INSERT INTO TableC(Name,UserID)
>SELECT Name, UserNO
>FROM TableB
>WHERE UserNo
> (SELECT UserID
> FROM TableA INNER JOIN
> TableB ON TableA.UserNo= TableB.UserNo) as UserNo
>
>I know I'm doing something stupid. Suggestions welcome

Opp! one more change
just a quick thought
I usually
SELECT Name, UserNO
INSERT INTO TableC
FROM TableB
WHERE UserNo
(SELECT UserID as UserNo
FROM TableA INNER JOIN
TableB ON TableA.UserNo= TableB.UserNo)

>
ml at 2007-11-11 23:54:19 >