473,698 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Command help for Unique records.

What is the syntax for an sql command to get the following.

I want to pull in a handful of fields from a table but one of the
fields needs to be unique.

For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?

I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?

TIA.

Feb 16 '07 #1
10 2793
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.

I want to pull in a handful of fields from a table but one of the
fields needs to be unique.

For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?

I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?

TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Feb 16 '07 #2
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.

This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.

Feb 19 '07 #3
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.

Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.

I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.

Feb 21 '07 #4
Simple workaround

Query 1 SELECT DISTINCT (CUSTOMER_NUMBE R)

then join that query to the main table and I think you will be able to
get what you want!
storrboy wrote:
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.


I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.
Feb 21 '07 #5
On Feb 21, 3:43 am, "purpleflas h" <k...@bgs.ac.uk wrote:
Simple workaround

Query 1 SELECT DISTINCT (CUSTOMER_NUMBE R)

then join that query to the main table and I think you will be able to
get what you want!

storrboy wrote:
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.
I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.- Hide quoted text -

- Show quoted text -
Does this command pull in all the fields of the table though?

Feb 21 '07 #6
On Feb 21, 12:13 pm, mscu...@gmail.c om wrote:
On Feb 21, 3:43 am, "purpleflas h" <k...@bgs.ac.uk wrote:


Simple workaround
Query 1 SELECT DISTINCT (CUSTOMER_NUMBE R)
then join that query to the main table and I think you will be able to
get what you want!
storrboy wrote:
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.
I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.- Hide quoted text -
- Show quoted text -

Does this command pull in all the fields of the table though?- Hide quoted text -

- Show quoted text -
To elaborate further, I am using the following command:

SELECT DISTINCTROW [EA_K]
FROM Customers;

I want to display all the fields in this query when the query runs and
use this to make a comparison against another table. When I run this,
it only displays the EA_K field. How do I get it to display the other
12 fields in the Customers table?

Feb 21 '07 #7
On Feb 21, 11:20 am, mscu...@gmail.c om wrote:
To elaborate further, I am using the following command:

SELECT DISTINCTROW [EA_K]
FROM Customers;

I want to display all the fields in this query when the query runs and
use this to make a comparison against another table. When I run this,
it only displays the EA_K field. How do I get it to display the other
12 fields in the Customers table?
Just drag and drop the astrix field into the design grid, that will
show all fields in that table.

Feb 21 '07 #8
On Feb 21, 12:20 pm, mscu...@gmail.c om wrote:
On Feb 21, 12:13 pm, mscu...@gmail.c om wrote:
On Feb 21, 3:43 am, "purpleflas h" <k...@bgs.ac.uk wrote:
Simple workaround
Query 1 SELECT DISTINCT (CUSTOMER_NUMBE R)
then join that query to the main table and I think you will be able to
get what you want!
storrboy wrote:
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.
I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.- Hide quoted text -
- Show quoted text -
Does this command pull in all the fields of the table though?- Hide quoted text -
- Show quoted text -

To elaborate further, I am using the following command:

SELECT DISTINCTROW [EA_K]
FROM Customers;

I want to display all the fields in this query when the query runs and
use this to make a comparison against another table. When I run this,
it only displays the EA_K field. How do I get it to display the other
12 fields in the Customers table?
>I am trying to use DISTINCTROW but to no avail. If I use DISTINCT, how
do I pull in the other fields?
The DISTINCT and DISTINCTROW clauses do not affect the actual columns
that are returned by a query. That is determined by the column names
listed before the FROM clause, e.g.

SELECT [Table1].[Column1], [Table1].[Column2] FROM [Table1]

or

SELECT [Table1].* FROM [Table1]

However, DISTINCT and DISTINCTROW affect the *rows* that are returned,
and it is important to note the difference. DISTINCT removes duplicate
rows by comparing just the selected columns, whereas DISTINCTROW
removes duplicate rows by comparing *all* columns in the source table
(or set of joined tables) regardless of which columns are to be
returned. So if you had a table of Cities and Provinces called
[CityProv], like this

[City] [Province]
Calgary AB
Edmonton AB
Vancouver BC
Victoria BC
Toronto ON
Montreal QC

You would see the following:

SELECT DISTINCT [CityProv].[Province] FROM [CityProv];

Province
--------
AB
BC
ON
QC

SELECT DISTINCTROW [CityProv].[Province] FROM [CityProv];

Province
--------
AB
AB
BC
BC
ON
QC
Feb 21 '07 #9
On Feb 21, 4:43 pm, "Gord" <g...@kingston. netwrote:
On Feb 21, 12:20 pm, mscu...@gmail.c om wrote:


On Feb 21, 12:13 pm, mscu...@gmail.c om wrote:
On Feb 21, 3:43 am, "purpleflas h" <k...@bgs.ac.uk wrote:
Simple workaround
Query 1 SELECT DISTINCT (CUSTOMER_NUMBE R)
then join that query to the main table and I think you will be able to
get what you want!
storrboy wrote:
On Feb 19, 9:20 am, mscu...@gmail.c om wrote:
On Feb 16, 12:29 pm, "storrboy" <storr...@sympa tico.cawrote:
On Feb 16, 12:50 pm, mscu...@gmail.c om wrote:
What is the syntax for an sql command to get the following.
I want to pull in a handful of fields from a table but one of the
fields needs to be unique.
For example, if I have a customer table and I want to get each unique
customer number but I also want to get the customer's name, address,
email address, etc. What is the syntax?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT,
how do I pull in the other fields?
TIA.
This is a little confusing, perhaps due to the tables not being
normalized better.
Why would a customer be in a 'customer table' more than once? Futher,
why would there be different information attached to the same cutomer
number? A customers table really should contain information about a
customer only once.
Trust me, the db I have to work with here was not created by me and
the relationships are set up very poorly.
I don't have a table like your to try things on, but if there is
different information attached to the same customer number then I
think the best you can do without normalizing is to use groupings.
This should merge all like records but duplicate the ones where one or
more fields are different.- Hide quoted text -
- Show quoted text -
Does this command pull in all the fields of the table though?- Hide quoted text -
- Show quoted text -
To elaborate further, I am using the following command:
SELECT DISTINCTROW [EA_K]
FROM Customers;
I want to display all the fields in this query when the query runs and
use this to make a comparison against another table. When I run this,
it only displays the EA_K field. How do I get it to display the other
12 fields in the Customers table?
I am trying to use DISTINCTROW but to no avail. If I use DISTINCT, how
do I pull in the other fields?

The DISTINCT and DISTINCTROW clauses do not affect the actual columns
that are returned by a query. That is determined by the column names
listed before the FROM clause, e.g.

SELECT [Table1].[Column1], [Table1].[Column2] FROM [Table1]

or

SELECT [Table1].* FROM [Table1]

However, DISTINCT and DISTINCTROW affect the *rows* that are returned,
and it is important to note the difference. DISTINCT removes duplicate
rows by comparing just the selected columns, whereas DISTINCTROW
removes duplicate rows by comparing *all* columns in the source table
(or set of joined tables) regardless of which columns are to be
returned. So if you had a table of Cities and Provinces called
[CityProv], like this

[City] [Province]
Calgary AB
Edmonton AB
Vancouver BC
Victoria BC
Toronto ON
Montreal QC

You would see the following:

SELECT DISTINCT [CityProv].[Province] FROM [CityProv];

Province
--------
AB
BC
ON
QC

SELECT DISTINCTROW [CityProv].[Province] FROM [CityProv];

Province
--------
AB
AB
BC
BC
ON
QC- Hide quoted text -

- Show quoted text -
yes, that is what I am getting something similar.

How could I write the SQL command to get the following?

[City] [Province] (Original Table)
Calgary AB
Edmonton AB
Vancouver BC
Victoria BC
Toronto ON
Montreal QC

[City] [Province] (Results desired)
Calgary AB
Vancouver BC
Toronto ON
Montreal QC

I want to eliminate the duplicate Provinces (AB,BC) yet display the
City and the Province.


Feb 22 '07 #10

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

Similar topics

12
1871
by: Jeff North | last post by:
I'm stumped and my brains are fried!!!! I have the following data +-------+------------------------------+------------+ | resID | FLEName | VersionNbr | +-------+------------------------------+------------+ | 1 | 35_laserdatandria2104.zip | 1.0 | | 2 | 35_laserdatandria2104.zip | 1.23 | | 3 | 35_microweb1.31.zip | 1.0 | | 4 | 35_microweb1.31.zip | 1.234 |
3
8995
by: Beat Scheidiger | last post by:
I do not quite understand this property. Everything is seems clear to me, when I read the corresponding help text. But in practice I have a question: Why are there 3 identical records in the following query (with property 'Unique records' = Yes)? SELECT DISTINCTROW tblCustomer., tblCustomer., tblCustomer., tblOrders., tblOrders., tblOrders.Artikel FROM tblCustomer INNER JOIN tblOrders ON tblCustomer. = tblOrders.;
5
8298
by: Terri | last post by:
I have a form with a multi-select combo. I dynamically build a SELECT statement, open a report, and set the recordsource to my dynamic SELECT statement. I count the records returned in the report by setting a text box to =Count(*). This works fine. Now I want to count the unique records in my report. I can dynamically create a SELECT statement that counts unique records. My statement looks like this: SELECT DISTINCT...
7
3784
by: Nicolae Fieraru | last post by:
I have two tables, they contain: Table1: ID1, Name1, Address1, Purchase1 Table2: ID2, Name2, Address2, Purchase2 I need a query which creates Table3 with content from Table1 and Table2. The records in Table3 have to contain all distinct records from Table1 and Table2 (records where Name2 and Address2 do not already exist in Table3) and Any help appreciated. I need these queries as a reference, I consider they
4
31254
by: kdubble | last post by:
Hi I am trying to get the results of a query to show only unique student records (not duplicates). Is there a simple way to make the criteria field do this? I am not too familiar with SQL. I have a student_info table, a session_info table, and a services_to_students table. What I'd like to do is query the tables to get a list of all students served between certain dates. Now, of course, between those dates,
3
4130
by: IsValidUN | last post by:
How do you select unique records? For example, if my data is like the following and I only want the repeated data (address information) to appear once for each theater_id. <xsl:for-each select="Table"> ???? <Table> <device_id>26</device_id> <serial_number>200102</serial_number> <is_active>true</is_active>
2
4445
by: srusskinyon | last post by:
I need some help getting unique records from our database! I work for a small non-profit homeless shelter. We keep track of guest information as well as what services we have offered for statistical purposes. I've been using Here's the situation: I have two main tables:
2
3551
Zwoker
by: Zwoker | last post by:
Greetings everyone, I have a problem that I hope has a simple solution. I am using MS Access 2003. I have a table that is a list of financial transactions. I am using a make table query over that table, and want to return a single record where multiple exist for the five fields that are keys on the table. The rule as to which record I want returned where many exist is to use the record with the most recent transaction date (a field on the...
10
2573
by: jmartmem | last post by:
Greetings, I have an ASP page with a 5x5 table embedded inside an Insert Record Form. This table contains several fields (mostly drop down list menus) and is used for corporate timekeeping (users record their daily hours by making selections from the list menus). My challenge is to figure out how the user can complete all rows of the table and click one button to submit the entire form AND have each row inserted as a unique record. In...
0
8676
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9029
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6522
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.