如何根据列获取两个表数据

时间:2015-01-13 09:16:32

标签: json sqlite cordova join inner-join

我们有两个表Table1和table2。表1有A,B,C列,表2有B,E,F列。

Table1                    Table2
A      B     C         B      E     F
raja   21   HYD        21     AP   60000000
raju   21   VJY        
ravi   21   BEG

我们需要的是

A      B    C     E    F
raja   21   HYD   AP   60000000
raju   21   VJY   AP   60000000 
ravi   21   BEG   AP   60000000 

所以我们尝试了这个

tx.executeSql('SELECT r.A as name,r.B as age,r.C as city,s.E as state,s.F as distance from table1 r Left JOIN table2 s on r.B=s.B',[],joinsuccess,errorCB);
    function joinsuccess(tx,result){
            var JOINLength = result.rows.length;
             for (var i=0; i<JOINLength; i++){
             console.log(result.rows.item(i).name);
             console.log(result.rows.item(i).age);
             console.log(result.rows.item(i).city);
             console.log(result.rows.item(i).state);
             console.log(result.rows.item(i).distance);
}
    }

但是我们只得到了

ravi   21   BEG  AP   60000000

0 个答案:

没有答案