I am looking to run an INSERT into a table using a WITH CLAUSE before the SELECT. I tried putting the WITH before the INSERT and before the SELECT but I am SQL is not liking the formatting.
Asked
Active
Viewed 87 times
-2
-
Welcome to StackOverflow! Please include an example of your code, any errors you are getting and expected results. – MhQ-6 Apr 02 '19 at 17:28
-
Please tag your question with the database you are using. – Gordon Linoff Apr 02 '19 at 17:44
1 Answers
1
Here is an example
INSERT
INTO values (a,b) //more values
WITH table AS
(
SELECT *
FROM table1
)
WITH table2 AS //from more tables
(
SELECT *
FROM table_2
)
SELECT t.value as a, t2.value as b
FROM table t
JOIN table2 t2 on t.value = t2.value //some join
WHERE t.value = 'X' //other stuff

MhQ-6
- 328
- 3
- 11