473,398 Members | 2,380 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,398 software developers and data experts.

Select Query

Hi All,

I have a Table1 with ID, Name, Address, Purchase.
I want to build a query which shows all the records from Table1 (only fields
ID, Name, Address), but there shouldn't be listed records which have the
same Name and Address (if a customer made two different purchases, he should
be listed only once).
Any help appreciated

Regards,
Nicolae
Nov 13 '05 #1
4 2044
I think I managed to build this query by myself, using the sample query
which John Winterbottom had the kindness to show me a few days ago.

SELECT a.*
FROM Table1 AS a
WHERE a.ID =
(
SELECT min(b.ID)
FROM Table1 AS b
WHERE b.Address = a.Address AND b.Name = a.Name
);

Regards,
Nicolae
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I have a Table1 with ID, Name, Address, Purchase.
I want to build a query which shows all the records from Table1 (only fields ID, Name, Address), but there shouldn't be listed records which have the
same Name and Address (if a customer made two different purchases, he should be listed only once).
Any help appreciated

Regards,
Nicolae

Nov 13 '05 #2
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I have a Table1 with ID, Name, Address, Purchase.
I want to build a query which shows all the records from Table1 (only fields ID, Name, Address), but there shouldn't be listed records which have the
same Name and Address (if a customer made two different purchases, he should be listed only once).
Any help appreciated

without the ID column you can do:

select [Name], Address
from Table1
group by [Name], Address

if you have more than one purchase for a customer, does it matter which ID
is returned? And if it does, what criteria will you use.- i.e. the first,
the last etc..
Nov 13 '05 #3
Hi John,

The real table actually has more fields than the one in my example. I need
to show in my query some of the fields. These fields contain information
about the customers mailing addresses. I don't need any other details from
the rest of the fields and I don't care too much which of the records will
be shown in the query (although I think the earlier ID is preffered).
It seems I oversimplified my problem and this causes some problems.
Here is an example closer to my real problem:

Table 1 with ID, FirstName, Surname, Address1, Address2, Suburb, State,
Mailout, Purchase

I need all the fields from all records from Table1 with unique Surname AND
Address1 (there are customers who made multiple purchases and they are
recorded in the table multiple times. But for example Address1 or State
might not be filled in into some records, while in others it is)

The query I built

SELECT a.*
FROM Table1 AS a
WHERE a.ID =
(
SELECT min(b.ID)
FROM Table1 AS b
WHERE b.Address1 = a.Address1 AND b.Surname = a.Surname
);

works fine for my sample table with 10 records, but stops responding for the
real table, with 228000 records...
(I run a sample database under Access97 on my computer, where I test my
queries and the real database on Access2002 on a remote computer, using
Remote Desktop Connection)

Regards,
Nicolae
"John Winterbottom" <as******@hotmail.com> wrote in message
news:2j************@uni-berlin.de...
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I have a Table1 with ID, Name, Address, Purchase.
I want to build a query which shows all the records from Table1 (only

fields
ID, Name, Address), but there shouldn't be listed records which have the
same Name and Address (if a customer made two different purchases, he

should
be listed only once).
Any help appreciated

without the ID column you can do:

select [Name], Address
from Table1
group by [Name], Address

if you have more than one purchase for a customer, does it matter which ID
is returned? And if it does, what criteria will you use.- i.e. the first,
the last etc..

Nov 13 '05 #4
Nicolae Fieraru wrote:
Hi John,

The real table actually has more fields than the one in my example. I need
to show in my query some of the fields. These fields contain information
about the customers mailing addresses. I don't need any other details from
the rest of the fields and I don't care too much which of the records will
be shown in the query (although I think the earlier ID is preffered).
It seems I oversimplified my problem and this causes some problems.
Here is an example closer to my real problem:

Table 1 with ID, FirstName, Surname, Address1, Address2, Suburb, State,
Mailout, Purchase

I need all the fields from all records from Table1 with unique Surname AND
Address1 (there are customers who made multiple purchases and they are
recorded in the table multiple times. But for example Address1 or State
might not be filled in into some records, while in others it is)

The query I built

SELECT a.*
FROM Table1 AS a
WHERE a.ID =
(
SELECT min(b.ID)
FROM Table1 AS b
WHERE b.Address1 = a.Address1 AND b.Surname = a.Surname
);

works fine for my sample table with 10 records, but stops responding for the
real table, with 228000 records...
(I run a sample database under Access97 on my computer, where I test my
queries and the real database on Access2002 on a remote computer, using
Remote Desktop Connection)

Regards,
Nicolae
"John Winterbottom" <as******@hotmail.com> wrote in message
news:2j************@uni-berlin.de...
"Nicolae Fieraru" <no****@please.cxm> wrote in message
news:40********@duster.adelaide.on.net...
Hi All,

I have a Table1 with ID, Name, Address, Purchase.
I want to build a query which shows all the records from Table1 (only


fields
ID, Name, Address), but there shouldn't be listed records which have the
same Name and Address (if a customer made two different purchases, he


should
be listed only once).
Any help appreciated

without the ID column you can do:

select [Name], Address
from Table1
group by [Name], Address

if you have more than one purchase for a customer, does it matter which ID
is returned? And if it does, what criteria will you use.- i.e. the first,
the last etc..


As I mentioned in an earlier response to you regarding slow
queries...build a second query. Make it a totals query. THen link your
current query to the totals query and remove your subquery.
Nov 13 '05 #5

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

Similar topics

1
by: Phil Powell | last post by:
Here is the scope of what I need to do; want: enrollment_year allowed (even if null) all of ica criteria:
21
by: John Fabiani | last post by:
Hi, I'm a newbie and I'm attempting to learn howto create a select statement. When I use >>> string1='18 Tadlock Place' >>> cursor.execute("SELECT * FROM mytest where address = %s",string1) All...
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
1
by: Andrew McNab | last post by:
Hi folks, I have a problem with an MS Access SQL query which is being used in an Access Report, and am wondering if anyone can help. Basically, my query (shown below) gets some records from a...
2
by: Pavel Stehule | last post by:
Hello, Pg make query 1. and 2. very fast (use index), but for query 3. dont use index. I can solve its using select union, but I readed so pg 7.5 don't problem with OR operator. I use cvs pg. I...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.