0

你能提供给我一些东西吗,如何推送两个不同但结构相同的表,我的意思是所有信息都是一样的,只是表名不同,mailings而且mailings_archive。一张桌子没问题

$query = sprintf("SELECT * FROM %smailings  WHERE hidden=0 AND draft=1 %sORDER BY category_id, mailing_segment", $this->dbprefix, $language);

$this->mailings[] = array('id' => $row->id,
                                      'mailing_naam' => $row->mailing_naam,
                                      'mailing_subject' => $row->mailing_subject,
                                      'mailing_from_name' => $row->mailing_from_name,
                                      'mailing_bounceaddress' => $row->mailing_bounceaddress,
                                      'mailing_body' => $row->mailing_body,
                                      'mailing_status' => $row->mailing_status,
                                      'mailing_segment' => $row->mailing_segment,
                                      'mailing_total_subscribers' => $row->mailing_total_subscribers,
                                      'mailing_total_sent' => $row->mailing_total_sent,
                                      'category_id' => $row->category_id,
                                      'utm_campaign' => $row->utm_campaign,
                                      'language' => $row->language);
        }                       

现在看起来是这样的,如何放入这个数组,另一个表数据?别忘了,每个字段都是一样的,只是表名不同。

4

2 回答 2

4
(SELECT * FROM %smailings  WHERE hidden=0 AND draft=1 %sORDER BY category_id, mailing_segment)
UNION
(SELECT * FROM another_table WHERE hidden=0 AND draft=1 %sORDER BY category_id, mailing_segment)

(select * from table1)
union
(select * from table2)

但这将导致一个无序的结果集,即使您在每个请求中放置“order by”,但这可能是最快的。

如果您需要在表 (1....8) 之间对所有内容进行排序,那么这是一种语法:

select * from table1
union
select * from table2 order by id

如果您想要两个单独的订单(例如一张桌子的 4...8,另一张桌子的 1..4):

select * from 
(select * from test1 order by id asc) as t1
union all
(select * from test2 order by id asc);
于 2013-03-29T15:07:14.997 回答
1

使用联合方法..

尝试查询:select 1 union select 2

于 2013-03-29T15:07:42.463 回答