Solved

query 2nd table based on results of 1st query

Posted on 2011-09-20
2
217 Views
Last Modified: 2012-05-12
table 1 --- master1   table2 --- custinput1

Based on the count of masterid I get from custinput1, I want to know how many posibilities are in master1.  Customer submits input file, which loads table custinput1.  The first query tells me how many records are linked to masterid in  custinput1.  I need to then take the masterid from the custinput1 file and compare how many more records are available in the master1 table.

This query tells me how many records are linked in custinput1:

select count(distinct masterid) from custinput1
  where exampleid = '3323'  and numberoflinked >0

Now I want to see how many are in master1. I'm trying...but it doesn't work., I get 0

select count (numberoflinked) from master1 where masterid in
(select count(distinct masterid) from custinput1
  where exampleid = '3323'  and numberoflinked >0)
0
Comment
Question by:abgail
2 Comments
 
LVL 11

Accepted Solution

by:
rajvja earned 500 total points
ID: 36568213
Try this

select count (numberoflinked) from master1 where masterid in
(select distinct masterid from custinput1
  where exampleid = '3323'  and numberoflinked >0)
 
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36568324
please give a sample data from both tables and the result that you are looking for...
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 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

15 Experts available now in Live!

Get 1:1 Help Now