473,385 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why is SELECT TOP 200 returning more rows than 200?

Here is my query:

Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 200 tblCallLog.tblCallLog_callDate, (tblClients.tblClients_firstName & ' ' & tblClients.tblClients_lastName & ' ' & tblClients.tblClients_sfx) AS clientName, 
  2. tblClients.tblClients_mailingAddress, (tblClients.tblClients_city & ', ' & tblClients.tblClients_state & ' ' & tblClients.tblClients_zip) AS addLine2, 
  3. tblCallLog.tblCallLog_dvdTractRequested, tblCallLog.tblCallLog_callDate, 
  4. tblCallLog.tblCallLog_dvdTractSent
  5. FROM tblClients INNER JOIN tblCallLog ON tblClients.tblClients_clientID = tblCallLog.tblCallLog_clientID
  6. WHERE (((tblClients.tblClients_mailingAddress) Is Not Null) 
  7. AND ((tblCallLog.tblCallLog_dvdTractRequested)=True) AND ((tblCallLog.tblCallLog_dvdTractSent) Is Null))
  8. ORDER BY tblCallLog.tblCallLog_callDate;
  9.  

Is there any reason why this would return 369 rows instead of the 200 I am asking for?
Mar 17 '11 #1
8 3403
Rabbit
12,516 Expert Mod 8TB
Probably because of duplicate rows. Try adding a unique field that would be unique across the join.
Mar 17 '11 #2
The callDate, dvdTractRequested, and dvdTractSent are all unique to one table. It's still returning more than what I ask for.
Mar 17 '11 #3
Rabbit
12,516 Expert Mod 8TB
You said it's unique to one table. It needs to be unique across tables.
Mar 17 '11 #4
okay, so now I selected clientID which is what the two tables are joined on, but it still is giving me 45 more than what I asked for... is that what you meant? a field that is the same on both tables?
Mar 17 '11 #5
Rabbit
12,516 Expert Mod 8TB
Not quite, it will need to be two or more fields that when used together, will make every record unique.
Mar 18 '11 #6
NeoPa
32,556 Expert Mod 16PB
Here's an illustration of the sort of issue that could cause more rows than stipulated appearing in a TOP N query (This is also explained in the SQL section of Help - See Finding Jet SQL Help).

Assuming a simple dataset of :
Expand|Select|Wrap|Line Numbers
  1. Field
  2.   A
  3.   B
  4.   C
  5.   C
  6.   C
  7.   D
  8.   E
and SQL of :
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 3
  2.          [Field]
  3. FROM     [MyTable]
  4. ORDER BY [Field]
The result set would be :
Expand|Select|Wrap|Line Numbers
  1. Field
  2.   A
  3.   B
  4.   C
  5.   C
  6.   C
As the third item in the sort order is C, it only specifies which values to include, not how many records. There are no more than three separate values included in the output.

Don't assume it works on the basis of the number of separate items though. The following result set, when the TOP predicate is set to 4, illustrates this :
Expand|Select|Wrap|Line Numbers
  1. Field
  2.   A
  3.   B
  4.   C
  5.   C
  6.   C
Notice the result sets are identical. Setting it to 6 would only add the value D. It will always show all records of the same value (within the sort order) whenever the nth value is duplicated.
Mar 18 '11 #7
So, "SELECT DISTINCT TOP 200" would help it seems?
Mar 18 '11 #8
NeoPa
32,556 Expert Mod 16PB
Nothing you've said so far leads me to believe that's what you're after.

If you look again at post #7 you'll see that the results would be quite different.

It's possible that's actually what you're after, but it's not what you've asked for at any point.
Mar 18 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Shuaib | last post by:
Is there any way for Oracle (using standard SQL rather than PL/SQL) to suppress the newline character when returning a list of rows. For example, if I have a table EMP with several records. When...
2
by: Dave Wijay | last post by:
Hi Does anybody know how to programmatically select items (rows) of a ListView in C#.NET Thanks in advanc Dave
1
by: dkode8 | last post by:
Heres my problem, the first part selects a row from the database, if there is no row with the criteria it inserts a row and then returns it, the problem is the IF statement that inserts the row,...
0
by: Raj Chudasama | last post by:
how can i select all rows in a datagrid also how can add checkbox to each of my rows in datagrid. I tried to use DataGridColumnStyle but failed try {
2
by: Kevin Hodgson | last post by:
I have a standard .NET Datagrid (Databound to a SQL Dataset), and I need to select all rows of the datagrid when a button is clicked, to allow a user to copy the data, and then paste it into Excel...
2
by: Ettenurb | last post by:
I was hoping someone has come across this and came up with a solution. We have upgraded our custom software to us Infragistics UltraWinGrid 2006 CLR 2.0. The code below worked with a previous...
2
by: mokazawa1 | last post by:
Hi, I'm using stored procedures in DB2 UDB 8.1.2. In this stored, I execute a select for update command, opening a cursor. Then I update the rows using fetch and current of. The problem is that...
1
by: arockiasamy | last post by:
hi, How to select multiple rows in a table using java script? and that selected rows must be deleted? i have done for single selection. how it can be for multiple? come on help me.. i...
3
by: khairulfnd | last post by:
i want to select multiple rows using a checkbox in a gridview in which it will be posted in another gridview
1
by: mbewers1 | last post by:
Hi there, I'm having a strange problem whereby I can execute a select query in Oracle SQL Developer that rerturns some rows but, when this same query is placed into C#, I get no results. I've...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.