SQL - 选择多个表以组合多个表

时间:2016-04-22 09:02:45

标签: sqlite

我想从多个表table1和table2中使用 { [functions]: , __proto__: { }, allestimento: "asd", antifurto: "meccanico", cavalliFiscali: 0, cilindrata: 0, dataAcquisto: [date] Fri Apr 22 2016 10:55:06 GMT+0200 (ora legale Europa occidentale), dataPrimaImmatricolazione: [date] Fri Apr 22 2016 10:55:06 GMT+0200 (ora legale Europa occidentale), dotazioni: "Abs", kilowat: 0, marcaVeicolo: "", massa: 0, modello: "asd", numeroVeicoli: null, riparo: "Garage", targa: "asd", tipoAlimnetazione: "Benzina", tipoVeicolo: "Auto", trasporto: "nessuno", valoreVeicolo: 0 } 来获取输出表,该表只是附加到table1的table2数据。如何构造SELECT *语句?

表1

SELECT * FROM

表2

id  model  datetime     driver   distance
---|-----|------------|--------|---------
1  | S   | 04/03/2009 | john   | 399 
2  | X   | 04/03/2009 | juliet | 244
3  | 3   | 04/03/2009 | borat  | 555

期望的输出:

id  model  datetime     driver   distance
---|-----|------------|--------|---------
4  | 3   | 03/03/2009 | john   | 300
5  | X   | 03/03/2009 | juliet | 200

2 个答案:

答案 0 :(得分:1)

试试这个可能会对你有帮助

    SELECT table1.model, table1.datetime, table1.driver, table1.distance FROM table1
    UNION ALL SELECT table2.model, table2.datetime, table2.driver, table2.distance FROM table2;

答案 1 :(得分:-1)

union语句从db中获取大数据变慢,你可以在这里使用join,

select * from table0 left join table2 on table0.b = table2.b where table2.col is not null