Avatar of fabiano petrone
fabiano petrone
Flag for Italy asked on

Help with MS SQL query on duplicates

Hello,
excuse the (probably) newbie question.
I must discover the "duplicates" in a list of books (where "duplicates" means books of same title and same location).
I've created the following query based on the items table of the database:

SELECT [bookId]
      ,[locationId]
	  , COUNT(*)
  FROM [database].[dbo].[items]
  GROUP BY
    [bookId], [locationId]
HAVING
    COUNT(*) > 1

Open in new window

     
it works well, but the info about the books is completed by other 2 tables:

1) [database].[dbo].[books]
that has [Id] = [database].[dbo].[items].[bookId]

2) [database].[dbo].[locations]
that has [Id] = [database].[dbo].[items].[locationId]

these tables contains other useful info that I want to include in my previous query, like:
[database].[dbo].[books].[title]
[database].[dbo].[locations].[location_name]
is it possible doing so?
Thanks a lot,
Fabiano
DatabasesMicrosoft SQL ServerSQL

Avatar of undefined
Last Comment
fabiano petrone

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Raja Jegan R

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Partha Mandayam

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
fabiano petrone

ASKER
Hi, Raja and Partha
Thanks a lot for your help!
I've marked both as solutions.
Take Care,
Fabiano
Your help has saved me hundreds of hours of internet surfing.
fblack61