Mysql Join and Order
I have 3 tables that have same columns,but different data ( deposits,withdrawals,transfers )
CREATE TABLE IF NOT EXISTS
withdrawals(idint(11) NOT NULL auto_increment,uservarchar(12) default NULL,amountdouble(12,2) default NULL,datetimestamp NULL default CURRENT_TIMESTAMP,timevarchar(50) default NULL,typevarchar(50) default NULL,statusvarchar(1) default '0',notesPRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I want to merge all 3 tables into 1 table and order them by all their dates and show a row only if 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:2开发者_如何转开发3 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
If I understand your question, this case is what the UNION operator is designed for. See http://www.w3schools.com/sql/sql_union.asp for more information.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论