2

I have table foo1 with columns UserID,TimeStamp; foo2 with columns userID,Level & table foo3 with columns userID,Timestamp.

I want to INSERT into foo1 all rows from foo3 where the UserID exists in table foo2.

I am getting ERROR 1242: Subquery returns more than 1 row with the following

INSERT into foo1 (UserID,TimeStamp)
SELECT  
(SELECT UserID from foo2 as UserID),

(SELECT foo3.TimeStamp
from foo3
inner join foo2
ON foo3.UserID=foo2.UserID) as TimeStamp
shree.pat18
  • 21,449
  • 3
  • 43
  • 63
Ram-man
  • 27
  • 5

1 Answers1

5

If you want to INSERT into foo1 all rows from foo3 where the UserID exists in table foo2 then you should go through this:

INSERT into foo1 (UserID,TimeStamp)
SELECT foo3.UserID,foo3.TimeStamp
from foo3
inner join foo2
ON foo3.UserID=foo2.UserID
moliware
  • 10,160
  • 3
  • 37
  • 47
logsv
  • 544
  • 6
  • 17