sql - Left Join without duplicate values from the left table when multiple values in right table -


the following query brings list of ids , list of times. it's bringing multimple left table because appears multiple in right table.

it brings this:

enter image description here

i want bring minimum value right table each id in left table.

any appreciated!

set language british  select dbo.employee.employeeid, substring(convert(varchar, clocktemp.clocktime, 108), 1, 5) clocktime  dbo.employee left join  (     select [clockid]       ,[employeeid]       ,[clocktypeid]       ,[clockdate]       ,[clocktime]      dbo.clock      dbo.clock.clockdate = dateadd(dd, 0, cast('07-11-2016' date)) , clock.clocktypeid=1 ) clocktemp on dbo.employee.employeeid = clocktemp.employeeid order dbo.employee.employeeid,clocktemp.clocktime 

maybe query work you. not need order clocktime minimum value brought through min aggregate.

i change clocktime field time if using sql 2008 can avoid substring convert.

set language british  select dbo.employee.employeeid, substring(convert(varchar, min(clocktemp.clocktime), 108), 1, 5) clocktime  dbo.employee left join  (     select [clockid]       ,[employeeid]       ,[clocktypeid]       ,[clockdate]       ,[clocktime]      dbo.clock      dbo.clock.clockdate = dateadd(dd, 0, cast('07-11-2016' date)) , clock.clocktypeid=1 ) clocktemp on dbo.employee.employeeid = clocktemp.employeeid group dbo.employee.employeeid order dbo.employee.employeeid 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -