1
declare @emp table
(
EmployeeId int, CompanyId int ,FirstName nvarchar(50),MiddleName nvarchar(50) ,LastName nvarchar(50)
)
insert into @emp select 1,1,'rahul','kumar','Sharma'
insert into @emp select 16,1,'nitin','','Sharma'
select * From @emp
declare @PayInformation table
(
EmployeeId int ,IsHourly bit ,PayFrequency nvarchar(50) ,Amount decimal(18,2),StandardHours decimal(18,2) ,Year int,Sequence int
)
insert into @PayInformation select 1,0,'monthly',40.00,40,2013,1
insert into @PayInformation select 1,0,'monthly',100.00,40,2013,2
insert into @PayInformation select 16,0,'monthly',100.00,40,2013,2
select * From @PayInformation
select * from @emp as e
inner join @PayInformation as p ON e.EmployeeId=p.EmployeeId
此連接語句給我3行加盟,因爲EmployeeId
1在PayInformation
表2行。但我想只加入具有最大序列號的行。根據我所期望的結果,它應該與員工1的序列號2一起加入。只有行有最大的序列號