SELECT DISTINCT yields more than SELECT 
Author Message
 SELECT DISTINCT yields more than SELECT

I am having a major problem with an SQL statement.  For some reason
whwenever I try to open a recordset it only returns one record though I
know with my test data it should return several.

The following

sql= "SELECT [Code] FROM [Jobs]"
set rs=db.openrecordset(sql)

...results in a recordset with 1 record (which has to be wrong!)

set rs=db.openrecordset("Jobs")

...results in a recordset with all records in the "Jobs" table (>10).

sql= "SELECT DISTINCT [Code] FROM [JOBS]"
set rs=db.openrecordset(sql)

...results in a recordset with 4 records (which is also correct)

What is wrong with my first sql line and how could SELECT DISTINCT ever
produce MORE records than just SELECT.

What's up?

(This code is just a sample of a larger issue which I need to stick to-
so please don't suggest alternate methods."

Thanks,
-Jamie G.



Thu, 09 Sep 1999 03:00:00 GMT  
 SELECT DISTINCT yields more than SELECT

For performance reasons, the jet engine will sometimes only return the
first record in a recordset, generated from a SQL statement.  To get the
true number of records returned, perform a move last to force a read of the
entire table and then check the recordcount.

--
David W. Forest
LAN Specialist
Information Technologies
Lear Corporation - Ford Division
SBN Level 2
http://www.concentric.net/~dforest/

If you're not scared, you don't understand.



Quote:
> I am having a major problem with an SQL statement.  For some reason
> whwenever I try to open a recordset it only returns one record though I
> know with my test data it should return several.

> The following

> sql= "SELECT [Code] FROM [Jobs]"
> set rs=db.openrecordset(sql)

> ...results in a recordset with 1 record (which has to be wrong!)

> set rs=db.openrecordset("Jobs")

> ...results in a recordset with all records in the "Jobs" table (>10).

> sql= "SELECT DISTINCT [Code] FROM [JOBS]"
> set rs=db.openrecordset(sql)

> ...results in a recordset with 4 records (which is also correct)

> What is wrong with my first sql line and how could SELECT DISTINCT ever
> produce MORE records than just SELECT.

> What's up?

> (This code is just a sample of a larger issue which I need to stick to-
> so please don't suggest alternate methods."

> Thanks,
> -Jamie G.



Fri, 10 Sep 1999 03:00:00 GMT  
 SELECT DISTINCT yields more than SELECT

Quote:

> For performance reasons, the jet engine will sometimes only return the
> first record in a recordset, generated from a SQL statement.  To get the
> true number of records returned, perform a move last to force a read of the
> entire table and then check the recordcount.

> --
> David W. Forest

Thanks, David.

You were absolutely correct and I wouldn't have figured it out for days!

-Jamie G.



Sat, 11 Sep 1999 03:00:00 GMT  
 SELECT DISTINCT yields more than SELECT

Quote:

> > For performance reasons, the jet engine will sometimes only return the
> > first record in a recordset, generated from a SQL statement.  To get the
> > true number of records returned, perform a move last to force a read of the
> > entire table and then check the recordcount.

> You were absolutely correct and I wouldn't have figured it out for days!

Hi,

If your recordset is very big I have found it to be quicker to run a
seperate SQL count function like this:

'===
sSQL = "SELECT COUNT(*) AS NumRecords FROM .... WHERE ...."

Set MyRS = MyDB.OpenRecordset(sSQL,dbOpenSnapshot)

lRecordCount = CLng(MyRS!NumRecords)

MyRS.Close
'===

Jon.

--

  |   |  | |  | Snail: 34 West Street, Banbury, Oxon, OX16 7HD, UK
\_/   \__/ |  | Phone: +44 1295 265109  http://www.evansoft.demon.co.uk/



Mon, 13 Sep 1999 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Change SELECT to SELECT DISTINCT?

2. SELECT works, but SELECT DISTINCT fails

3. Selecting view code yields window title bar only

4. SELECT DISTINCT and memo field problem?

5. Does Access support SELECT Count(DISTINCT fieldname) ...

6. VB select distinct Fax, Co_nam from tableA doesn't

7. Why does SELECT COUNT(DISTINCT price) .. not work

8. Oracle Select DISTINCT used to work, now does not

9. How to select distinct into a combo

10. Problem using SELECT DISTINCT

11. Select distinct on 1 field but returns multiple fields

12. select count distinct doesnt work

 

 
Powered by phpBB® Forum Software