Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL server 2005 sql query problem

Posted on 2007-03-30
2
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
ksaul earned 500 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how the fundamental information of how to create a table.

604 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