?
Solved

SQL server 2005 sql query problem

Posted on 2007-03-30
2
Medium Priority
?
186 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

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…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Suggested Courses

770 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