Reputation: 3
"Make a query that having all orders by employees from employeeUK in the orderUK table"
my table of employeeUK:
select *
into employeeUK
from Employees
where Country = 'UK'
then i want to make the orderUK table:
select *
into orderUKcoba
from Orders o join employeeUK e
where (e.EmployeeID = o.EmployeeID)
but what i got is
Incorrect syntax near the keyword 'where'.
how to correct that?
Upvotes: 0
Views: 51
Reputation: 14928
How to insert into in 2 table?
You could do that by using OUTPUT Clause
as the following:
INSERT INTO TargetTable1(Column1, ...)
OUTPUT INSERTED.Column1, ... INTO TargetTable2
SELECT Column1, ...
FROM SourceTable;
Here is a simple example on db<>fiddle
Upvotes: 1
Reputation: 5141
You have to ON clause instead of WHERE clause while joining the table, please use below query
select *
into orderUKcoba
from Orders o join employeeUK e
on (e.EmployeeID = o.EmployeeID);
Upvotes: 0
Reputation: 50163
JOIN
requires ON
clause :
select o.col, . . . , e.col, . . . -- Qualify all column names explicitly
into orderUKcoba
from Orders o join
employeeUK e
on e.EmployeeID = o.EmployeeID;
Upvotes: 0
Reputation: 1269443
The correct syntax uses ON
:
select *
into orderUKcoba
from Orders o join
employeeUK e
on e.EmployeeID = o.EmployeeID;
This will return an error, because at least one column is duplicated (EmployeeId
) and tables cannot have duplicate column names. But that is not the question you asked.
You should be listing out the columns explicitly for a new table.
Upvotes: 0