Solved

SQL server 2005 sql query problem

Posted on 2007-03-30
2
184 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 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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

717 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