我在SQLite数据库中有两个表A和B.表A看起来像这样:
| id | name | description | created |
|------|---------------|---------------|--------------|
| 1 | "Something" | "Something" | 1466266963 |
| 2 | "Something" | "Something" | 1466266965 |
| 3 | "Something" | "Something" | 1466266967 |
| 4 | "Something" | "Something" | 1466266969 |
| 5 | "Something" | "Something" | 1466266971 |
| 6 | "Something" | "Something" | 1466266975 |
表B就是这样:
| id | title | content | created |
|------|---------------|---------------|--------------|
| 1 | "Something" | "Something" | 1466266951 |
| 2 | "Something" | "Something" | 1466266953 |
| 3 | "Something" | "Something" | 1466266954 |
| 4 | "Something" | "Something" | 1466266956 |
| 5 | "Something" | "Something" | 1466266957 |
| 6 | "Something" | "Something" | 1466266978 |
我想在两张桌子之间找到最老的4张。
所以在这个例子中我会得到类似的东西:
| id | title | name | content | description | created |
|------|---------------|---------------|---------------|---------------|--------------|
| 6 | "Something" | | "Something" | | 1466266975 |
| 6 | | "Something" | | "Something" | 1466266975 |
| 5 | | "Something" | | "Something" | 1466266975 |
| 4 | | "Something" | | "Something" | 1466266975 |
我尝试SELECT A.*, B.* FROM A, B ORDER BY created DESC LIMIT 4
但是我得到一个空结果(虽然我的表不是空的)。
我也看过JOIN,但没有成功。
有什么想法吗?感谢。
答案 0 :(得分:0)
使用union all
select * from(
select * from a
union all
select * from b
) t
order by created DESC LIMIT 4