MySQL在联合查询中添加`status`字段会破坏它

时间:2017-11-05 00:20:18

标签: mysql union

以下查询有效:

select * from
(select id, sender, null as recipient, amount, `timestamp`
from ethTransactions
where userId = ?
union all
select id, sender, recipient, amount, `timestamp`
from sofTransactions where userId = ?) b
order by `timestamp` asc`

产生输出:

|id|sender         |recipient  |amount |timestamp          |
|1 |ajdoaidjoiwjdaq|           |0.03222|2017-11-08 03:09:11|
|1 |opiyptropyirpyi|dqwuebhdnwq|1.02223|2017-10-08 04:09:11|

但如果我为两个选择添加状态,则不会:

select * from
(select id, `status`, sender, null as recipient, amount, `timestamp`
from ethTransactions
where userId = ?
union all
select id, `status`, sender, recipient, amount, `timestamp`
from sofTransactions where userId = ?) b
order by `timestamp` asc`

我得到1行的输出,其中只包含值id的{​​{1}}字段,该字段在我的数据中甚至不存在。我在101周围加上反复思考,认为这可能是一个保留的词,但它并没有帮助。如何修复第二个查询以输出与第一个相同的数据(添加状态字段)?

0 个答案:

没有答案