Solved

SQL Sub Query

Posted on 2013-05-23
3
173 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now