troubleshooting Question

Help with MS SQL query on duplicates

Avatar of fabiano petrone
fabiano petroneFlag for Italy asked on
DatabasesMicrosoft SQL ServerSQL
3 Comments2 Solutions162 ViewsLast Modified:
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
     
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
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros