Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2005, 10:44 AM
Authorized User
 
Join Date: Jun 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL count query not giving correct results

Hi,

I have 2 tables 'ecastdata' and 'ecastops'. I am running a COUNT on the number of records from the 'ecastdata' table with a specific ID from both tables.

I am excluding certain email addresses from both tables. The email addresses in the 'ecastdata' table are in one column: |Email|.
The 'ecastops' table has the email addresses in seperate columns, for example: |EcastOpSeed1|EcastOpSeed2|EcastOpSeed3|

The problem is the query does not seem to get a value from the column: |EcastOpSeed3|
When I run the query the total count result is 7734 and should be 7733 records.

Plese Help!!!

Here is the query I'm using:

SELECT COUNT(*) AS intTotal FROM ecastdata where ecastdata.EcastID = 46 AND
(ecastdata.Email NOT LIKE '%yahoo.com' AND ecastdata.Email NOT LIKE '%hotmail.com' AND
 ecastdata.Email NOT LIKE
(SELECT ecastops.EcastOpSeed1 FROM ecastops WHERE ecastops.EcastOpID = 46) AND
 ecastdata.Email NOT LIKE
(SELECT ecastops.EcastOpSeed2 FROM ecastops WHERE ecastops.EcastOpID = 46) AND
 ecastdata.Email NOT LIKE
(SELECT ecastops.EcastOpSeed3 FROM ecastops WHERE ecastops.EcastOpID = 46))

 
Old March 16th, 2005, 04:22 AM
Authorized User
 
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this...

SELECT COUNT(*) AS intTotal
FROM ecastdata
WHERE ecastdata.EcastID = 46
AND ecastdata.Email NOT LIKE '%yahoo.com'
AND ecastdata.Email NOT LIKE '%hotmail.com'
AND ecastdata.Email NOT IN
(
 SELECT ecastops.EcastOpSeed1 EmailOpSeed FROM ecastops WHERE ecastops.EcastOpID = 46
 UNION
 SELECT ecastops.EcastOpSeed2 FROM ecastops WHERE ecastops.EcastOpID = 46
 UNION
 SELECT ecastops.EcastOpSeed3 FROM ecastops WHERE ecastops.EcastOpID = 46
)

Cheers,
Pooja Falor
 
Old March 16th, 2005, 07:06 AM
Authorized User
 
Join Date: Jun 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That worked great Pooja.

Thanks very much for your help :)



Quote:
quote:Originally posted by poojafalor
 try this...

SELECT COUNT(*) AS intTotal
FROM ecastdata
WHERE ecastdata.EcastID = 46
AND ecastdata.Email NOT LIKE '%yahoo.com'
AND ecastdata.Email NOT LIKE '%hotmail.com'
AND ecastdata.Email NOT IN
(
 SELECT ecastops.EcastOpSeed1 EmailOpSeed FROM ecastops WHERE ecastops.EcastOpID = 46
 UNION
 SELECT ecastops.EcastOpSeed2 FROM ecastops WHERE ecastops.EcastOpID = 46
 UNION
 SELECT ecastops.EcastOpSeed3 FROM ecastops WHERE ecastops.EcastOpID = 46
)

Cheers,
Pooja Falor





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL query on Access db giving error DesignsOnline.co.uk Access 2 November 17th, 2006 05:06 PM
SQL count query not giving correct results hman SQL Server 2000 1 March 15th, 2005 01:15 PM
SQL query for count programmer_kay ADO.NET 1 April 18th, 2004 02:48 AM
SQL query for count programmer_kay SQL Language 1 April 17th, 2004 07:30 PM
Query not returning correct results from database Jams30 PHP Databases 5 November 7th, 2003 08:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.