views:

19

answers:

1

Hello, I have 3 tables that have same columns,but different data ( deposits,withdrawals,transfers )

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) default NULL, status varchar(1) default '0', notes PRIMARY 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: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  A: 

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.

Dante617
Thanks a milion !!! The UNION operator solved all my problems !!!
nevergone