Product...
0 comment
Alexandre Dechêne
This extension is now unpublished from Marketplace. You can choose to uninstall it. Overview Q & A Product...
Extensions for Mozilla Firefox
1 comment
Attention! All content on the site, including, but not limited to, articles, images, videos and code, is provided "as is" and without warranty. If you have a problem with a video, please email [email protected] instead of using the comments. Certain browsers may not render some videos properly. Thanks for understanding. This video is for demonstration purposes only, to help you understand how to install.NET Runtime and develop add-ons.Q:
SQL - get results with multiple joins
I'm having issues constructing a proper SQL query for this problem.
I'm using SQL Server 2014
This is the scenario:
tblA - ID, tblB - ID
tblB - ID, tblC - ID
tblC - ID
tblB is a one to many relation to tblC.
Each time I insert data to tblB, it also inserts a relation to tblC (I am not sure if this is what is meant by one-to-many, if you look at the picture above, you will see what I mean by relation).
With my query I would like to find rows in tblA which have only IDs that are in tblB and tblC and which are joined by more than 1 relation in tblC.
This is what I have:
SELECT a.ID
FROM tblA AS a
WHERE a.ID NOT IN
(SELECT MAX(b.ID) FROM tblB AS b)
INNER JOIN tblC AS c ON a.ID = c.ID
GROUP BY a.ID
HAVING COUNT(DISTINCT c.ID) > 1
The problem is that my query returns all IDs, but no rows with IDs which are in both tblB and tblC.
Can you tell me what I'm doing wrong here and how I should solve it?
A:
I think this is what you are looking for:
FROM
Related links:
Comments