mysql union使用

来源:互联网 发布:即时通讯软件 编辑:程序博客网 时间:2024/05/22 15:19


需求: 一个是帖子回复表,一个是发现回复表,web需要两个表内容显示一块,并能按照时间排序

select * from ( select 2 as table_type,id,`comment` as content,uid,c_id as post_id,add_time  from {$this->_commentTable} where uid={$params['uid']} and is_del=0 union
         select 1 as table_type,id,content,uid,i_id as post_id,add_time from {$this->_interlocutionTable}  where uid={$params['uid']} and is_del=0 and `type`=1
        ) as reply  order by add_time desc {$whereLimit}

原创粉丝点击