使用common列比较Sqlite中的两个表

时间:2013-10-06 15:37:41

标签: android

我正在创建一个应用程序,它会按时间顺序自动列出一天的来电和短信。我完成了使用服务存储短信和调用数据库的代码。我有2张桌子:

Table Call(number, name, call_type, call_duration, date, time, time_in_milliseconds (long)) 
Table Sms(number, name, message, date, time, time_in_milliseconds (long)) 

我需要根据time_in_milliseconds比较两个表格,然后按照time_in_milliseconds增加的顺序检索整个行并设置为文本视图。

1 个答案:

答案 0 :(得分:1)

如果我理解正确,您可以使用此代码:

        ourDatabase.rawQuery("SELECT number, name, call_type, call_duration, date, time, time_in_milliseconds " +
            " FROM Call " +
            " UNION " +
            " SELECT number, name, message, date, time, time_in_milliseconds " +
            " FROM Sms " +
            " ORDER BY time_in_milliseconds", null);