Solved

SQL server 2005 sql query problem

Posted on 2007-03-30
2
178 Views
Last Modified: 2010-03-19
I am having problems writing this sql query, help would be much appreciated:

I have two tables
ageBracketPercent and ageBracketCount
ageBracketPercent has the following fields
mediaId
lowAge
highAge
percentage

ageBracketCount has these fields
mediaId
lowAge
highAge
count

I am trying to retrieve all records in ageBracketCount that are not
represented in agePercentCount so something like this

select * from ageBracketCount
where [the combined key (mediaId, lowAge, highAge) does not exist in ageBracketPercent)]
(I wonder why this SQL query is not working!;-)

so in other words, if I have this data in the tables
ageBracketPercent:
mediaId      lowAge      highAge percentage
1          1              10            50
1          25           100        30

and this data in ageBracketCount
mediaId      lowAge      highAge count
1          1              10            10000
1          10               25            50000
1          25           100            1000

I want to get to the middle record with this data
mediaId      lowAge      highAge count
1          10               25          50000
0
Comment
Question by:HugoForte
2 Comments
 
LVL 10

Accepted Solution

by:
ksaul earned 125 total points
ID: 18826817
SELECT a.*
FROM ageBracketCount a
LEFT OUTER JOIN ageBracketPercent p ON a.mediaId = p.mediaId AND a.lowAge = p.lowAge
WHERE p.mediaId IS NULL
0
 

Author Comment

by:HugoForte
ID: 18826899
LoL;-) thanks a lot, I dont' know why I was complicating it!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

758 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

19 Experts available now in Live!

Get 1:1 Help Now