数据库为MySQL
我现在有两张表
一张表是technology_article,另外一张是tenant_message
其中technology_article有id, title, content, create_date, update_date, status字段
内容
0, 王子的生活, 不好, 2020-01-10, 2021-01-15, 0
1, 贵妇人, 人生的希望, 2020-01-11, 2021-01-12, 1
2, 省市德阳的, 不一样, 2021-01-18, 2021-02-31, 1
tenant_message有id, content, create_date, update_date, articleID字段
articleID字段对应technology_article的id
内容
0, 渔网有意思, 2020-01-10, 2021-01-15, 0
1, 无趣, 2020-01-11, 2021-01-12, 1
2, 有意思, 2020-01-10, 2021-01-15, 1
3, 无趣, 2020-01-11, 2021-01-12, 1
4, 无趣, 2020-01-11, 2021-01-12, 1
5, 无趣, 2020-01-11, 2021-01-12, 1
我现在希望将technology_article和tenant_message两个数据一起查询,然后按照更新时间update_date排序
如果status的状态为0,则不查询tenant_message中的关联数据
最后的结果期望如下
0, 王子的生活, 不好, 2020-01-10, 2021-01-15,null
1, 贵妇人, 人生的希望, 2020-01-11, 2021-01-12,null
2, 无趣, null, 2020-01-11, 2021-01-12, 1
3, 有意思, null, 2020-01-10, 2021-01-15, 1
4, 无趣, null, 2020-01-11, 2021-01-12, 1
5, 无趣, null, 2020-01-11, 2021-01-12, 1
6, 无趣, null, 2020-01-11, 2021-01-12, 1
7, 省市德阳的, 不一样, 2021-01-18, 2021-02-31,null
select * from tenant_message where articleID in (select id from technology_article where status = 1)
union all
select * from technology_article