Solved

SQL Sub Query

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

17 Experts available now in Live!

Get 1:1 Help Now