Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Join 2 table and get max value

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2011-04-14 : 21:44:38
Dear All,

How can i get below output from this 2 table?
Thank you.


Table A
--------
ID Menu CanAccess ( 1 / 0 )
1 Test 0
2 Go 0
3 Jum 0
4 Ki 0
5 Pa 0

Table B
--------
ID CanAccess ( 1 / 0)
2 1
4 1
5 1

Output
------
1 Test 0
2 Go 1
3 Jum 0
4 Ki 1
5 Pa 1


Regards,
Micheale

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-04-14 : 22:01:35
[code]
select ID, Menu, max(CanAccess)
from
(
select ID, Menu, CanAccess from TableA
union all
select ID, NULL, CanAccess from TableB
) d
group by ID, Menu
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2011-04-14 : 22:20:35
Dear KH Tan,

Tqvm.

Regards,
Micheale
Go to Top of Page
   

- Advertisement -