+ 2

Finding duplicate values in a sql table

Hey fam, I need your help, i'm a bit stuck on a certain task which needs me to Write a query that gives me all drivers that are linked to more than one vehicle (Give the driver id, name, surname, the number of vehicles that the driver is linked to) my current query: SELECT TOP 100 DT.DRIVERID , DPN.FIRSTNAME , DPN.LASTNAME , SS.SERIALPRIMARY VEHICLEREG , SS.SPECDSC AS VEHICLEDESCRIPTION FROM EXDDRIVERTABLE DT INNER JOIN DIRPERSON DP ON DP.RECID = DT.PARTY INNER JOIN DIRPERSONNAME DPN ON DPN.PERSON = DP.RECID INNER JOIN EXDLINKDRIVERSTRUCT LNK ON LNK.DRIVERPARTYRECID = DT.PARTY AND ((LNK.TODATETIME >= GETDATE() OR LNK.TODATETIME = '1900-01-01 00:00:00.000') AND LNK.FROMDATETIME < GETDATE()) INNER JOIN BBLSPECSTRUCT SS ON SS.RECID = LNK.STRUCTRECID WHERE SS.DATAAREAID = 'ALL' BBLSPECSTRUCT SS ON SS.RECID = LNK.STRUCTRECID WHERE SS.DATAAREAID = 'ALL'

8th Jan 2020, 1:11 PM
Jones Navela
Jones Navela - avatar
1 ответ
+ 4
Hi man. I think you could do it grouping by DRIVERID with a Having clause "count(*) > 1", and then doing a Select over that first Select.
9th Jan 2020, 12:25 AM
Javier Ballesteros
Javier Ballesteros - avatar