473,386 Members | 1,823 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,386 software developers and data experts.

Distinct vs DistinctRow?

Can someone explain the difference between these 2 queries?

"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"

Thanks,
Fred Zuckerman

Nov 13 '05 #1
5 53303
From the help file:

DISTINCT:
Omits records that contain duplicate data in the selected fields. To be
included in the results of the query, the values for each field listed in
the SELECT statement must be unique. For example, several employees listed
in an Employees table may have the same last name. If two records contain
Smith in the LastName field, the following SQL statement returns only one
record that contains Smith:
SELECT DISTINCT
LastName
FROM Employees;

If you omit DISTINCT, this query returns both Smith records.

If the SELECT clause contains more than one field, the combination of values
from all fields must be unique for a given record to be included in the
results.

The output of a query that uses DISTINCT is not updatable and does not
reflect subsequent changes made by other users.

DISTINCTROW:
Omits data based on entire duplicate records, not just duplicate fields. For
example, you could create a query that joins the Customers and Orders tables
on the CustomerID field. The Customers table contains no duplicate
CustomerID fields, but the Orders table does because each customer can have
many orders. The following SQL statement shows how you can use DISTINCTROW
to produce a list of companies that have at least one order but without any
details about those orders:
SELECT DISTINCTROW CompanyName
FROM Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY CompanyName;

If you omit DISTINCTROW, this query produces multiple rows for each company
that has more than one order.

DISTINCTROW has an effect only when you select fields from some, but not
all, of the tables used in the query. DISTINCTROW is ignored if your query
includes only one table, or if you output fields from all tables.
Basically, the difference is whether the entire record is distinct
(including fields not returned by the query) or if just the output of the
query has no duplicates.
--
Wayne Morgan
MS Access MVP
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in message
news:GQ****************@newssvr21.news.prodigy.com ...
Can someone explain the difference between these 2 queries?

"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"

Thanks,
Fred Zuckerman

Nov 13 '05 #2
> "Fred Zuckerman" <Zu********@sbcglobal.net> wrote in message
Can someone explain the difference between these 2 queries?
"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"
Thanks,
Fred Zuckerman

"Wayne Morgan" <co***************************@hotmail.com> wrote in message> Basically, the difference is whether the entire record is distinct
(including fields not returned by the query) or if just the output of the
query has no duplicates.
--
Wayne Morgan
MS Access MVP


Ok. I think I got it. Great.
Thanks,
Fred
Nov 13 '05 #3
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in
news:Yo*****************@newssvr21.news.prodigy.co m:
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in message
> Can someone explain the difference between these 2 queries?
> "Select Distinct id, account, lastname, firstname from table1"
> and
> "Select DistinctRow id, account, lastname, firstname from
> table1" Thanks,
> Fred Zuckerman


"Wayne Morgan" <co***************************@hotmail.com> wrote
in message>
Basically, the difference is whether the entire record is
distinct (including fields not returned by the query) or if just
the output of the query has no duplicates.


Ok. I think I got it. Great.


A couple of other things:

A DISTINCT query is never editable.

A DISTINCTROW query will often be editable when a plain SELECT is
not.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #4
On Fri, 24 Jun 2005 21:59:24 GMT, "David W. Fenton"
<dX********@bway.net.invalid> wrote:
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in
news:Yo*****************@newssvr21.news.prodigy.c om:
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in message
> Can someone explain the difference between these 2 queries?
> "Select Distinct id, account, lastname, firstname from table1"
> and
> "Select DistinctRow id, account, lastname, firstname from
> table1" Thanks,
> Fred Zuckerman


"Wayne Morgan" <co***************************@hotmail.com> wrote
in message>
Basically, the difference is whether the entire record is
distinct (including fields not returned by the query) or if just
the output of the query has no duplicates.


Ok. I think I got it. Great.


A couple of other things:

A DISTINCT query is never editable.

A DISTINCTROW query will often be editable when a plain SELECT is
not.


Funny enough, in Access 97, DISTINCTROW is sometimes required to make a query
editable, while in Access 2000, the same query will only be editable if
DISTINCTROW is ommitted. In Access 2000 and above, I have yet to find any
cases where DISTINCTROW was of any use.
Nov 13 '05 #5

This is a fairly brilliant demonstration of your copy and paste abilities,
Wayne. Wear your MVP badge with pride!

"Wayne Morgan" <co***************************@hotmail.com> wrote in message
news:6f****************@newssvr30.news.prodigy.com ...
From the help file:

DISTINCT:
Omits records that contain duplicate data in the selected fields. To be
included in the results of the query, the values for each field listed in
the SELECT statement must be unique. For example, several employees listed
in an Employees table may have the same last name. If two records contain
Smith in the LastName field, the following SQL statement returns only one
record that contains Smith:
SELECT DISTINCT
LastName
FROM Employees;

If you omit DISTINCT, this query returns both Smith records.

If the SELECT clause contains more than one field, the combination of
values from all fields must be unique for a given record to be included in
the results.

The output of a query that uses DISTINCT is not updatable and does not
reflect subsequent changes made by other users.

DISTINCTROW:
Omits data based on entire duplicate records, not just duplicate fields.
For example, you could create a query that joins the Customers and Orders
tables on the CustomerID field. The Customers table contains no duplicate
CustomerID fields, but the Orders table does because each customer can
have many orders. The following SQL statement shows how you can use
DISTINCTROW to produce a list of companies that have at least one order
but without any details about those orders:
SELECT DISTINCTROW CompanyName
FROM Customers INNER JOIN Orders
ON Customers.CustomerID = Orders.CustomerID
ORDER BY CompanyName;

If you omit DISTINCTROW, this query produces multiple rows for each
company that has more than one order.

DISTINCTROW has an effect only when you select fields from some, but not
all, of the tables used in the query. DISTINCTROW is ignored if your query
includes only one table, or if you output fields from all tables.
Basically, the difference is whether the entire record is distinct
(including fields not returned by the query) or if just the output of the
query has no duplicates.
--
Wayne Morgan
MS Access MVP
"Fred Zuckerman" <Zu********@sbcglobal.net> wrote in message
news:GQ****************@newssvr21.news.prodigy.com ...
Can someone explain the difference between these 2 queries?

"Select Distinct id, account, lastname, firstname from table1"
and
"Select DistinctRow id, account, lastname, firstname from table1"

Thanks,
Fred Zuckerman


Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John M | last post by:
Hi, The line below is used to feed a combobox. (It is from a database which is used to log pupil behaviour!) The 'incidents' table contains a list of students who have been involved in incidents....
18
by: mathilda | last post by:
My boss has been adamant that SELECT DISTINCT is a faster query than SELECT all other factors being equal. I disagree. We are linking an Access front end to a SQL Server back end and normally are...
1
by: nfrodsham | last post by:
In Microsoft's help literature, it states: "You can filter out non-unique rows by using the DISTINCT option of an aggregate function" I am trying to do this in Access 2003 with the COUNT...
4
by: dubing | last post by:
Hello everyone, I've tried both DISTINCT or DISTINCTROW in the following query in a PHP script. But the results still contain duplicate records as show below. DISTINCT works fine on single...
6
by: dick | last post by:
Am working with MS Access 2003 & tables downloaded from Oracle. Am not a GURU, more of a hacker, but have done a bit of everything in many languages/programs/etc. I have data fields in 2 tables...
2
by: johnhanis | last post by:
I'm using a Visual Basic front end with an SQL query to select some data from a MS Access database. I have a table named Tithes with Columns of TitheDate Tither No Total Tithes Faith Promise...
3
lwwhite
by: lwwhite | last post by:
I've got a a datasheet subform that gets its data from a SELECT DISTINCT query. The data is not editable. When I remove the DISTINCT qualifier from the query, the data is editable, but of course I...
2
by: peridian | last post by:
Hello, I understand what DISTINCT and DISTINCTROW do in Access, and that they don't exist in other SQL versions. Could somebody explain the thinking behind why you need the DISTINCTROW keyword...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.