我有3个表有相同的列,但不同的数据(存款,取款,转账)
CREATE TABLE IF NOT EXISTS withdrawals(id int(11)NOT NULL auto_increment,user varchar(12)default NULL,amount double(12,2)default NULL,date timestamp NULL default CURRENT_TIMESTAMP,time varchar(50)default NULL,type varchar(50)默认为NULL,status varchar(1)默认为'0',注释PRIMARY KEY(id))ENGINE = MyISAM DEFAULT CHARSET = latin1 AUTO_INCREMENT = 1;
我想将所有3个表合并为1个表并按所有日期对它们进行排序,并仅在user ='$ user'时显示一行
Example if table 1 has this data
id user amount date time type status notes
2 vveer 142.00 2010-04-01 03:05:01 PayPal 2 deposit
3 test11 116.00 2010-04-01 10:33:23 PayPal 2 deposit
Example if table 2 has this data
id user amount date time type status notes
3 vveer 142.00 2009-04-01 03:05:01 PayPal 2 withdraw
7 test11 112.00 2010-04-12 10:33:23 PayPal 2 withdraw
Example if table 3 has this data
id user amount date time type status notes
5 test11 133.00 2010-03-01 10:33:23 PayPal 2 transfer
7 test11 123.00 2010-02-01 10:33:23 PayPal 2 transfer
I want to show all data for user test11 ordered by dates(is like putting all the dates together and ordering by 1 date column ) .
3 test11 112.00 2010-04-12 10:33:23 PayPal 2 withdraw
7 test11 116.00 2010-04-01 10:33:23 PayPal 2 deposit
5 test11 133.00 2010-03-01 10:33:23 PayPal 2 transfer
5 test11 123.00 2010-02-01 10:33:23 PayPal 2 transfer
1 回答
如果我理解你的问题,这个案例就是UNION运算符的设计目的 . 有关更多信息,请参见http://www.w3schools.com/sql/sql_union.asp .