简体   繁体   English

sql:从两个表中排序并按日期排序

[英]sql: sort from two tables and order by date

I met a problem in my iPhone App - I create tow tables with sqlite3:我在我的 iPhone 应用程序中遇到了一个问题 - 我用 sqlite3 创建了两个表:

create table A (Name varchar(50), Added datetime);
create table B (UserID varchar(50), Username varchar(50), Created datetime);

I need to get all the values of the two tables ordered by time, which is like:我需要获取按时间排序的两个表的所有值,例如:

Alen  2011-06-25 17:56:00
12    Fire      2011-06-26 17:56:00
Bale  2011-07-01 17:56:00

As you see there is no relationship between of the tables, I've no idea about it.如您所见,表之间没有关系,我对此一无所知。

The app is undergoing, and it's difficult to redesign the DB.该应用程序正在进行中,并且很难重新设计数据库。 I'd like to know the solution based on the current DB schema (this is also the boss's requirement).我想知道基于当前数据库模式的解决方案(这也是老板的要求)。

SELECT NULL AS Col1, Name AS Col2, Added AS Col3
FROM A
UNION ALL 
SELECT UserID AS Col1, Username AS Col2, Created AS Col3
FROM B
ORDER BY 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM