sql - Get DISTINCT record using INNER JOIN -
i have follwong query on multi tables
select distinct b.boxbarcode [box barcode], (select case when b.imagescount null 0 else b.imagescount end) [total images], s.stagename [current stage] ,d.docuementtypename [document type], u.username [start user],uu.username [finished user] [dbo].[operations] o inner join dbo.lkup_stages s on o.stageid=s.id inner join dbo.lkup_users u on u.id=o.startuserid left join dbo.lkup_users uu on uu.id=o.finisheduserid inner join boxes b on b.id=o.boxid inner join lkup_documenttypes d on d.id = b.doctypeid b.isexportfinished = 0
when select count boxes table isexportfinished = 0
got count 42 records, when run above qoury got 71 records, want 42 records in boxes table retrived.
you doing one-to-many join, i.e. @ least 1 of tables have multiple rows match join criteria.
step 1 find table(s) give "duplicates".
once have done may able fix problem adding additional criteria join. i'm taking guess same boxid
occurs several times in operations
table. if case need decide operation
row want select , update sql accordingly.
Comments
Post a Comment