如何从db [HTML5]中获取两个相同的字段数据?

时间:2011-09-05 05:26:07

标签: html sqlite html5 enyo

this.db.transaction(function (tx)
            {
                tx.executeSql('SELECT tsk.*, cont.firstName, cont.lastName ,cont1.firstName, cont1.lastName, list.listId FROM tbl_tasks tsk, tbl_contacts cont,tbl_contactequests cont1, tbl_lists list WHERE  (tsk.assignedId=0 or tsk.assignedId=cont.contactId or tsk.assignedId=cont1.contactRequestId) and tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" and list.listId=tsk.listId and list.listId='+window.defaultlistid+' group by tsk.taskId', [], enyo.bind(this,this.queryResponse), enyo.bind(this,this.errorHandler));//call queryResponse
            }.bind(this));

现在您可以看到cont.firstName(表tbl_contacts)& cont1.firstName具有(表tbl_contactequests)具有相同字段的名字

for (var i = 0; i < len; i++)
            {

                list[i]     =   results.rows.item(i);
                fname       =   list[i].firstName;
                lname       =   list[i].lastName;
                fullname    =   fname+' '+lname;
                //alert(fullname);
                if(list[i].assignedId==0)
                {list[i].name = '';}
                else
                {list[i].name=fullname;}

            }

通过这个循环,我可以改变tbl_contacts字段firstname的第一个值。现在假设我无法访问tbl_contactequests表firstname。

1 个答案:

答案 0 :(得分:2)

对SQL查询使用AS关键字:

    'SELECT tsk.*, 
            cont.firstName AS cFirstName, 
            cont.lastName ,
            cont1.firstName AS c1FirstName, 
            cont1.lastName, list.listId 
     FROM tbl_tasks tsk, tbl_contacts cont,
          tbl_contactequests cont1, tbl_lists list 
     WHERE  (tsk.assignedId=0 OR tsk.assignedId=cont.contactId OR
            tsk.assignedId=cont1.contactRequestId) AND 
            tsk.taskCategoryType != "INBOX_NOT_ACCEPTED" AND 
            list.listId=tsk.listId AND list.listId='+window.defaultlistid+' 
     GROUP BY tsk.taskId'