简体   繁体   中英

inner join after insert into temp table

I can run two separate SQL statement where the first INSERT INTO a temp table and the second SQL statement runs an INNER JOIN between the temp table and another table.

I was trying to run the two statements in a single SQL statement but I am getting syntax error (using access).

first statement:

INSERT INTO temp SELECT id from t1 where a_column='Yes'

second statement:

SELECT * from t2 INNER JOIN t2.id = temp.id

Is there a way to run the two in a single statement?

These are two very different operations. You can't insert and output data all at once (at least not in Access).

If you are doing this through queries you'll need to make a second query. Each query in Access can only execute one statement.

You also need to specify the two tables you are joining together. Each statement is independent and has not bearing of reference for what came before.

SELECT * 
FROM t2 
INNER JOIN temp on t2.id = temp.id

Though depending on what you wish to accomplish (I'm not sure why you need a temp table) you might get away with this

SELECT * 
FROM t2 
INNER JOIN t1 ON t2.id = t1.id
WHEREt1.a_column='Yes'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM