2010-09-08 63 views
0

我有3個表有相同的列,但不同的數據(存款,取款,轉賬)Mysql的加入和秩序

CREATE TABLE IF NOT EXISTS withdrawalsid INT(11)NOT NULL的auto_increment, user VARCHAR(12)默認NULL,amount 雙(12,2)默認NULL,date 時間戳NULL默認 CURRENT_TIMESTAMP,time VARCHAR(50)默認NULL,type VARCHAR(50)默認NULL,status VARCHAR(1)默認的 '0',notes PRIMARY KEY (id))ENGINE = DEFAULT的MyISAM CHARSET = LATIN1 AUTO_INCREMENT = 1;

我想所有3個表合併爲1臺,責令由他們所有的日期,並顯示一排只有當用戶=「$用戶」

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 
+0

爲什麼模式不是這樣開始的?您應該只有一個事務表和一個類型列,而不是3個不同的表。 – NullUserException 2010-09-08 14:09:36

回答