Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inner join in Insert query?

Tags:

c#

sql

insert

I wanna do something like this:

insert into TableA 
   (val1,val2) 
values
   ("value",(select top 1 tableB.X from tableB where tableB.Y=@Y))

I get this error:

Subqueries are not allowed in this context. Only scalar expressions are allowed

How to stop that error?

like image 912
user278618 Avatar asked Apr 24 '26 11:04

user278618


2 Answers

Assuming you're using SQL Server:

insert into tableA 
  (val1, val2) 
select top 1 'value', tableB.x from tableB where tableB.Y = @y 
like image 80
ristonj Avatar answered Apr 26 '26 00:04

ristonj


I assume you have to use directly the insert into TABLE select... syntax.
No "values" in this case.
People above have been faster than me but I agree with their proposals

like image 43
pierroz Avatar answered Apr 26 '26 00:04

pierroz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!