我有2个查询,其结果是我尝试插入到新表中。
Query1: Class Name Age City
A1 Jill 21 New York
Query2: Class Name Age City
A2 Joe 25 Paris
现在,当我再次运行查询时,城市可以更改,但我想在新表中插入只有city =“New York”的记录。
所以,像INSERT INTO FinalTable(Name,Age,City)
SELECT
QUERY1.CLASS, QUERY1.NAME, QUERY1.AGE, QUERY1.CITY,
QUERY2.CLASS, QUERY2.NAME, QUERY2.AGE, QUERY2.CITY
FROM QUERY1, QUERY2
WHERE (QUERY1.CITY="NEW YORK" OR QUERY2.CITY="NEW YORK")
在一次迭代中,只有一个查询将城市作为纽约。
我收到重复的目的地名称错误
答案 0 :(得分:0)
你可以这样使用
INSERT INTO FinalTable(Name, Age, City)
SELECT tab.* FROM(
SELECT
QUERY1.CLASS, QUERY1.NAME, QUERY1.AGE, QUERY1.CITY,
FROM QUERY1
WHERE QUERY1.CITY="NEW YORK"
UNION ALL
SELECT
QUERY2.CLASS, QUERY2.NAME, QUERY2.AGE, QUERY2.CITY
FROM QUERY2
WHERE QUERY2.CITY="NEW YORK"
) tab