473,779 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL query similar to DISTINCT help please

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 that I want, and these are linked by 2
intermediary tables, say tblA, tblB, tblC, & tblD. The fields I want
are in A & D, B & C contain the linking fields.

I put this together in Access Design view, made the links, and it sort
of works. But, I get too many rows as output. I want exactly 1 row of
output for each row of tblA. I just want to pick up additional
attributes from tblD that should have been in tblA in the first place -
uggg.

Currently the linking is A->B->C->D. It turns out the A->B links are
one-to-many Any one of these many A->B links will get to the right
stuff in tablD.

I've tried DISTINCT, TOP 1, DISTINCTROW, but I guess I need this
distinct function to be on tablB and nowhere else.

Do I need a SELECT within a SELECT?

In English what I what is: take a row from tblA, take it pointer to
tblB, pick any one row from tblB that matches, follow its pointer to
tblC, again pick any one row that matches, follow its pointer to tblD
and return a specified filed to the final output.

Any help appreciated!!!

Dick Penny

Jun 16 '06 #1
6 4693
Could you cut and paste your SQL so we don't have to either guess or be
psychic? I'm not very good at guessing, and my psychic ability is not a
strong point.

Larry Linson
Microsoft Access MVP

"dick" <d_*****@usa.ne t> wrote in message
news:11******** **************@ r2g2000cwb.goog legroups.com...
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 that I want, and these are linked by 2
intermediary tables, say tblA, tblB, tblC, & tblD. The fields I want
are in A & D, B & C contain the linking fields.

I put this together in Access Design view, made the links, and it sort
of works. But, I get too many rows as output. I want exactly 1 row of
output for each row of tblA. I just want to pick up additional
attributes from tblD that should have been in tblA in the first place -
uggg.

Currently the linking is A->B->C->D. It turns out the A->B links are
one-to-many Any one of these many A->B links will get to the right
stuff in tablD.

I've tried DISTINCT, TOP 1, DISTINCTROW, but I guess I need this
distinct function to be on tablB and nowhere else.

Do I need a SELECT within a SELECT?

In English what I what is: take a row from tblA, take it pointer to
tblB, pick any one row from tblB that matches, follow its pointer to
tblC, again pick any one row that matches, follow its pointer to tblD
and return a specified filed to the final output.

Any help appreciated!!!

Dick Penny

Jun 16 '06 #2
It would help if you posted some of the SQL strings you've tried.

"dick" <d_*****@usa.ne t> wrote in message
news:11******** **************@ r2g2000cwb.goog legroups.com...
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 that I want, and these are linked by 2
intermediary tables, say tblA, tblB, tblC, & tblD. The fields I want
are in A & D, B & C contain the linking fields.

I put this together in Access Design view, made the links, and it sort
of works. But, I get too many rows as output. I want exactly 1 row of
output for each row of tblA. I just want to pick up additional
attributes from tblD that should have been in tblA in the first place -
uggg.

Currently the linking is A->B->C->D. It turns out the A->B links are
one-to-many Any one of these many A->B links will get to the right
stuff in tablD.

I've tried DISTINCT, TOP 1, DISTINCTROW, but I guess I need this
distinct function to be on tablB and nowhere else.

Do I need a SELECT within a SELECT?

In English what I what is: take a row from tblA, take it pointer to
tblB, pick any one row from tblB that matches, follow its pointer to
tblC, again pick any one row that matches, follow its pointer to tblD
and return a specified filed to the final output.

Any help appreciated!!!

Dick Penny

Jun 16 '06 #3
* dick:
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 that I want, and these are linked by 2
intermediary tables, say tblA, tblB, tblC, & tblD. The fields I want
are in A & D, B & C contain the linking fields.

I put this together in Access Design view, made the links, and it sort
of works. But, I get too many rows as output. I want exactly 1 row of
output for each row of tblA. I just want to pick up additional
attributes from tblD that should have been in tblA in the first place -
uggg.

Currently the linking is A->B->C->D. It turns out the A->B links are
one-to-many Any one of these many A->B links will get to the right
stuff in tablD.

I've tried DISTINCT, TOP 1, DISTINCTROW, but I guess I need this
distinct function to be on tablB and nowhere else.

Do I need a SELECT within a SELECT?

In English what I what is: take a row from tblA, take it pointer to
tblB, pick any one row from tblB that matches, follow its pointer to
tblC, again pick any one row that matches, follow its pointer to tblD
and return a specified filed to the final output.

Any help appreciated!!!

Dick Penny


Use an aggregate query. Use Group By for the field in TableA that you
want to appear only once. For the other fields, use First or Max.

--
Randy Harris
tech at promail dot com
I'm pretty sure I know everything that I can remember.
Jun 16 '06 #4

Larry Linson wrote:
Could you cut and paste your SQL so we don't have to either guess or be
psychic? I'm not very good at guessing, and my psychic ability is not a
strong point.

Larry Linson
Microsoft Access MVP


OK, here the whole mess, this gives 7 rows with 6 identical columns.
Two of the "wheres" are just to pair data quantity down, while the
third on "file" is because I want the linkage to only utilize those
rows (in the 1st link table).

SELECT DISTINCT OPENPAGES_SX_AU DIT3.RESOURCEID ,
OPENPAGES_SX_AU DIT3.WHO, OPENPAGES_SX_AU DIT3.WHEN,
OPENPAGES_SX__A SSOCIATION.CHIL DTYPE,
OPENPAGES_SX_PR OCESS.PR_MEGA_P ROCESS,
OPENPAGES_SX_PR OCESS.PR_DESCRI PTION
FROM ((OPENPAGES_SX_ AUDIT3 INNER JOIN OPENPAGES_SX__A SSOCIATION ON
OPENPAGES_SX_AU DIT3.RESOURCEID = OPENPAGES_SX__A SSOCIATION.PARE NT)
INNER JOIN OPENPAGES_SX__P ROCESS_FILE ON
OPENPAGES_SX__A SSOCIATION.CHIL D = OPENPAGES_SX__P ROCESS_FILE.FIL E_ID)
INNER JOIN OPENPAGES_SX_PR OCESS ON
OPENPAGES_SX__P ROCESS_FILE.PRO CESS_ID = OPENPAGES_SX_PR OCESS.PROCESS_I D
WHERE (((OPENPAGES_SX _AUDIT3.RESOURC EID)="4798") AND
((OPENPAGES_SX_ AUDIT3.WHEN)>#6/6/2006#) AND
((OPENPAGES_SX_ _ASSOCIATION.CH ILDTYPE)="File" ));

Realizing where I think things have gone wrong, I omitted the first
table, and began with link tbl1 into link tbl2 into "required data
column" table. Thinking that if I could control the one-to-manyness
problem in a smaller task, I could always expand it.

This SQL is:

SELECT DISTINCT OPENPAGES_SX__A SSOCIATION.PARE NT,
OPENPAGES_SX__A SSOCIATION.CHIL DTYPE,
OPENPAGES_SX_PR OCESS.PR_MEGA_P ROCESS,
OPENPAGES_SX_PR OCESS.PR_DESCRI PTION
FROM (OPENPAGES_SX__ ASSOCIATION INNER JOIN OPENPAGES_SX__P ROCESS_FILE
ON OPENPAGES_SX__A SSOCIATION.CHIL D =
OPENPAGES_SX__P ROCESS_FILE.FIL E_ID) INNER JOIN OPENPAGES_SX_PR OCESS ON
OPENPAGES_SX__P ROCESS_FILE.PRO CESS_ID = OPENPAGES_SX_PR OCESS.PROCESS_I D
WHERE (((OPENPAGES_SX __ASSOCIATION.P ARENT)="4798") AND
((OPENPAGES_SX_ _ASSOCIATION.CH ILDTYPE)="File" ));

I get effectively the same results as previously.

Then I tried a query on ONLY the tbl that has the one-to-many links, it
too fails (for me). To simplify:

Link table1
----------------

A | a1 | dog
A | a2 | dog
A | a3 | dog
B | b1 | dog
B | b2 | dog
C | C1 | dog

I asked for a DISTINCT query showing columns 1 & 3, and I rec'd all 6
rows where I expected only
A | dog
B | dog
C | dog

Am I using DISTINCT wrong?
Is this problem because all these tables came from Oracle?
Where all the link fields are in fact "text" not integers?
There are NO relationships in my *.mbd, I just drag & drop linkages I
want in design view.

Please keep the comments coming.

Dick

Jun 17 '06 #5

Larry Linson wrote:
Could you cut and paste your SQL so we don't have to either guess or be
psychic? I'm not very good at guessing, and my psychic ability is not a
strong point.

Larry Linson
Microsoft Access MVP


OK, here the whole mess, this gives 7 rows with 6 identical columns.
Two of the "wheres" are just to pair data quantity down, while the
third on "file" is because I want the linkage to only utilize those
rows (in the 1st link table).

SELECT DISTINCT OPENPAGES_SX_AU DIT3.RESOURCEID ,
OPENPAGES_SX_AU DIT3.WHO, OPENPAGES_SX_AU DIT3.WHEN,
OPENPAGES_SX__A SSOCIATION.CHIL DTYPE,
OPENPAGES_SX_PR OCESS.PR_MEGA_P ROCESS,
OPENPAGES_SX_PR OCESS.PR_DESCRI PTION
FROM ((OPENPAGES_SX_ AUDIT3 INNER JOIN OPENPAGES_SX__A SSOCIATION ON
OPENPAGES_SX_AU DIT3.RESOURCEID = OPENPAGES_SX__A SSOCIATION.PARE NT)
INNER JOIN OPENPAGES_SX__P ROCESS_FILE ON
OPENPAGES_SX__A SSOCIATION.CHIL D = OPENPAGES_SX__P ROCESS_FILE.FIL E_ID)
INNER JOIN OPENPAGES_SX_PR OCESS ON
OPENPAGES_SX__P ROCESS_FILE.PRO CESS_ID = OPENPAGES_SX_PR OCESS.PROCESS_I D
WHERE (((OPENPAGES_SX _AUDIT3.RESOURC EID)="4798") AND
((OPENPAGES_SX_ AUDIT3.WHEN)>#6/6/2006#) AND
((OPENPAGES_SX_ _ASSOCIATION.CH ILDTYPE)="File" ));

Realizing where I think things have gone wrong, I omitted the first
table, and began with link tbl1 into link tbl2 into "required data
column" table. Thinking that if I could control the one-to-manyness
problem in a smaller task, I could always expand it.

This SQL is:

SELECT DISTINCT OPENPAGES_SX__A SSOCIATION.PARE NT,
OPENPAGES_SX__A SSOCIATION.CHIL DTYPE,
OPENPAGES_SX_PR OCESS.PR_MEGA_P ROCESS,
OPENPAGES_SX_PR OCESS.PR_DESCRI PTION
FROM (OPENPAGES_SX__ ASSOCIATION INNER JOIN OPENPAGES_SX__P ROCESS_FILE
ON OPENPAGES_SX__A SSOCIATION.CHIL D =
OPENPAGES_SX__P ROCESS_FILE.FIL E_ID) INNER JOIN OPENPAGES_SX_PR OCESS ON
OPENPAGES_SX__P ROCESS_FILE.PRO CESS_ID = OPENPAGES_SX_PR OCESS.PROCESS_I D
WHERE (((OPENPAGES_SX __ASSOCIATION.P ARENT)="4798") AND
((OPENPAGES_SX_ _ASSOCIATION.CH ILDTYPE)="File" ));

I get effectively the same results as previously.

Then I tried a query on ONLY the tbl that has the one-to-many links, it
too fails (for me). To simplify:

Link table1
----------------

A | a1 | dog
A | a2 | dog
A | a3 | dog
B | b1 | dog
B | b2 | dog
C | C1 | dog

I asked for a DISTINCT query showing columns 1 & 3, and I rec'd all 6
rows where I expected only
A | dog
B | dog
C | dog

Am I using DISTINCT wrong?
Is this problem because all these tables came from Oracle?
Where all the link fields are in fact "text" not integers?
There are NO relationships in my *.mbd, I just drag & drop linkages I
want in design view.

Please keep the comments coming.

Dick

Jun 17 '06 #6
Randy's advice seems good to me.

Larry
Jun 18 '06 #7

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

Similar topics

4
10237
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline View Query: Select Sq from ( Select substr(to_date(End_Date,"DD-MON-YYYY"),4), End_Date, Rank() Over (Partition by substr(to_date(End_Date,"DD-MON-YYYY"),4) Order by End_Date) As Sq
2
32120
by: Jai | last post by:
Say the following are the columns of a table A B C D E F Can a aggregate function like sum be applied to A like sum(a) and then order by b and c similarly aggregate function on d and group by e and f using a single query... Regards, Jai
4
1880
by: sah | last post by:
I need some help with the following query: DECLARE @SRV VARCHAR(20), @date smalldatetime SET @SRV = (select @@servername) SET @date = '20040901' select Srv_Name = @SRV, DB_Name = 'DB_NAME', Table_Name = 'Info_Table', Date_of_Records = @date, count(*) AS 'Actual Total' ,
9
2768
by: Ed_No_Spam_Please_Weber | last post by:
Hello All & Thanks in advance for your help! Background: 1) tblT_Documents is the primary parent transaction table that has 10 fields and about 250,000 rows 2) There are 9 child tables with each having 3 fields each, their own PK; the FK back to the parent table; and the unique data for that table. There is a one to many relation between the parent and each of the 9 child rows. Each child table has between 100,000 and 300,000
12
5627
by: Irene | last post by:
Hi all again, Well, I have my Athletics database with Athletes, Competitions, Scores tables. I have a ranking query where I get back the list of the competitions-athletes and scores opportunely sorted. I also want to be able to: 1) Select just the top <n> best scores
7
1917
by: Riley DeWiley | last post by:
I am continually amazed by SQL's ability to humble me .... I have a toy query into a toy database that looks just like this: SELECT . FROM f, fw, w WHERE f.id = fw.fid and fw.wid = w.id and w.id in (((((select distinct w.id from w where w.x in ('a', 'b') ))))) GROUP BY . HAVING count(f.id) = (select count(id) from (((((select distinct w.id from w
4
3408
by: Miks | last post by:
The database scheme consists of four relations: Product(maker, model, type) PC(code, model, speed, ram, hd, cd, price) Laptop(code, model, speed, ram, hd, screen, price) Printer(code, model, color, type, price) The relation "Product" shows the maker, model number, and type (pc, laptop, or printer). It is assumed that model numbers are unique for all the makers and product types. For each model number specifying pc
7
3733
by: Wildster | last post by:
Hi, I’ve setup a table which contains records with multiple duplicated time fields (tblTime_Slots) i.e. ID Time_Slot 1 08:00 2 08:00 3 09:00 4 09:00 etc…
4
4587
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
9632
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
9471
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10071
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7478
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
5372
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
5501
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
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.