Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a query

Status
Not open for further replies.

algomes

Programmer
Aug 2, 2002
20
PT
SELECT A, B,
(SELECT COUNT(*) FROM T1 WHERE X1=Y1) AS C,
(SELECT COUNT(*) FROM T1 WHERE X1=Y1) AS D
FROM T2
WHERE MYDATE < '2002-10-14'

How can I make this query return data where C<>D?
 
If I read the query correctly, C and D will ALWAYS be equal since they both run the same query against T1. Am I missing something here?
 
SELECT A, B,
(SELECT COUNT(*) FROM T1 WHERE X1=Y1) AS C,
(SELECT COUNT(*) FROM T1 WHERE X2=Y2) AS D
FROM T2
WHERE MYDATE < '2002-10-14'

I'm sory for the error. The query above is the one I want.
 
I don't think this will help, but it is another way to write the query. Problem is there is no relationship between T1 and T2.



SELECT A, B, c.ccount,d.dcount
FROM T2,
(SELECT COUNT(*) ccount FROM T1 WHERE X1=Y1) C,
(SELECT COUNT(*) dcount FROM T1 WHERE X2=Y2) D
WHERE MYDATE < '2002-10-14'
and c.ccount <> d.dcount


Is there some relation between T1 and T2? Otherwise, I don't know that this will get you what you really want. You need a relation between T1 and T2 so you can join on the link and get the right data.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top