Solved

SQL Sub Query

Posted on 2013-05-23
3
179 Views
Last Modified: 2013-05-23
Hi,

I expect this is a nice easy one.

I have a statement

SELECT a, Sum(b), Sum(c)
FROM tbl1
Group By a

But I want to restrict the results to certain records found in tbl2

Thanks
0
Comment
Question by:BananaFury
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 39190801
>But I want to restrict the results to certain records found in tbl2
Then join tbl1 to tbl2, and the ON clause would spell out the relationship between the two tables such that anything that doesn't match in both tables would not be returned.

SELECT tbl1.a, Sum(tbl1.b), Sum(tbl1.c)
FROM tbl1
   JOIN tbl2 ON tbl1.ID = tbl2.tbl1_ID    -- How the tables are joined 
WHERE tbl2.some_value = "something"   -- If you want to restrict it further based on specific criteria
GROUP BY tbl1.a

Open in new window

0
 

Author Closing Comment

by:BananaFury
ID: 39190940
Great, thanks!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39190942
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question