0
SELECT DATE_FORMAT(MAX(a.EffectiveDate),'%d-%m-%Y') AS `Date`,
CONCAT(a.FirstNm,' ',IFNULL(a.MiidleNM,' '),' ',IFNULL(a.LastNM,' ')) AS `EmployeeName`,
`b`.`BranchName` AS `Branch`
FROM `tbl_employeemaster` AS `a`
JOIN `tbl_branch` AS `b` ON a.BrnNm = b.idBranch
UNION
SELECT DATE_FORMAT(MAX(c.EffectiveDate),'%d-%m-%Y') AS `Date`,
CONCAT(c.FirstNm,' ',IFNULL(c.MiidleNM,' '),' ',IFNULL(c.LastNM,' ')) AS `EmployeeName `,
`d`.`BranchName` AS `Branch`
FROM `tbl_employeehistory` AS `c`
JOIN `tbl_branch` AS `d` ON c.BrnNm = d.idBranch
...顯示兩行是輸出:的mysql:在單行
Date EmployeeName Branch
-------------------------------------
15-01-2011 ABCD Bangalore
10-10-2010 ABCD Magalore
...但我想輸出如下圖所示
EmployeeName Branch Date previous Branch Date
ABCD Bangalore 15-01-2011 Mangalore 10-10-2010
請張貼表模式。 – 2011-01-14 06:04:39
你應該真的考慮爲你的表使用更長的別名。單字母表的別名是更容易一些,但是當你再回到這個在六個月內嘗試讀取你的查詢,你會跟你有更多的描述性名稱。 – 2011-01-14 06:07:17