Read 209 times | Created 2013-01-11 12:33:32 | Updated 2013-01-11 12:37:45 | | |

 

USE `test`;

DROP TABLE IF EXISTS `tbl_A`;
CREATE TABLE IF NOT EXISTS `tbl_A` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table tbl_A',
  `content` varchar(30) NOT NULL COMMENT 'isi A',
  `tgl` DATE NOT NULL COMMENT 'tanggal tbl A',
  PRIMARY KEY(`id`)
) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data A';

INSERT INTO `tbl_A`(`id`,`content`,`tgl`) VALUES
(NULL,'saya suka makan','2012-12-30'),(NULL,'saya suka koding','2013-01-06');

DROP TABLE IF EXISTS `tbl_B`;
CREATE TABLE IF NOT EXISTS `tbl_B` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table tbl_B',
  `content` varchar(30) NOT NULL COMMENT 'isi B',
  `tgl` DATE NOT NULL COMMENT 'tanggal tbl B',
  PRIMARY KEY(`id`)
) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data B';

INSERT INTO `tbl_B`(`id`,`content`,`tgl`) VALUES
(NULL,'saya suka koding','2012-12-31'),(NULL,'saya suka koprol','2013-01-04');

SELECT * FROM
(SELECT *, 'A' AS tbl FROM tbl_A
UNION
SELECT *, 'B' AS tbl FROM tbl_B) AS C
ORDER BY tgl;