473,666 Members | 2,367 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

List Many to Many results once each?

Hi All,

I have built a search page(asp) in dreamweaver for a friend with a used
records store and website. The results page lists all recordings their
database(ms access 2002) holds with(or similar to) the desired title
entered by the user. The database uses a many to many relationship
between tblArtists, tblLINKArtist_R ecording and tblRecordings to allow
every artist to have many recordings associated with them and every
recording to have many artists associated with them(the example I use
here is 'Nobody Told Me' which was recorded by John Lennon and Yoko
Ono). Hence the 'Inner Join' used in the select statement shown below.

"SELECT tblArtists.Arti stName, tblRecordings.R ecordingID,
tblRecordings.T itle, tblRecordings.P rice, FROM tblRecordings INNER JOIN
(tblArtists INNER JOIN tblLINKArtist_R ecording ON tblArtists.Arti stID =
tblLINKArtist_R ecording.Artist ID) ON tblRecordings.R ecordingID =
tblLINKArtist_R ecording.Record ingID
WHERE tblRecordings. Title Like'%Nobody Told Me%'"

It works to return the record twice and is formatted in a search
results page pretty much as follows:

Title: End of the Line
Artist: John Lennon
Recording ID: 1066
Price: $12

Title: End of the Line
Artist: Yoko Ono
Recording ID: 1066
Price: $12

How can I get it to return that title(linked to the RecordingID) only
once with the associated Artists listed in one of the fields as
follows?

Title: End of the Line
Artist(s): Yoko Ono, John Lennon
Recording ID: 1066
Price: $12

Any ideas?

Regards,

Penny.

Aug 16 '06 #1
6 1390
an*********@hot mail.com wrote:
Hi All,

How can I get it to return that title(linked to the RecordingID) only
once with the associated Artists listed in one of the fields as
follows?

Title: End of the Line
Artist(s): Yoko Ono, John Lennon
Recording ID: 1066
Price: $12
There's no easy way to do this from an external program. In an Access
application, you could create a custom VBA function to do this, but
custom VBA functions are not usable by external applications.
What you could do is something similar to the solution posted here:
http://groups.google.com/group/micro...343e624?hl=en&

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 16 '06 #2
Thanks for your response Bob.

I see why you're suggesting to use an array. I've got a feeling however
that I need the original recordset which returns all the titles and
also a second recordset that runs for every single one of the results
to see if there is more than one associated artist and if so to get the
page to list them.

If a page returns 500 resultant titles then the second recordset would
have to be built 500 times!

Does this make any sense?

Penny

Bob Barrows [MVP] wrote:
an*********@hot mail.com wrote:
Hi All,

How can I get it to return that title(linked to the RecordingID) only
once with the associated Artists listed in one of the fields as
follows?

Title: End of the Line
Artist(s): Yoko Ono, John Lennon
Recording ID: 1066
Price: $12
There's no easy way to do this from an external program. In an Access
application, you could create a custom VBA function to do this, but
custom VBA functions are not usable by external applications.
What you could do is something similar to the solution posted here:
http://groups.google.com/group/micro...343e624?hl=en&

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 16 '06 #3
an*********@hot mail.com wrote:
Thanks for your response Bob.

I see why you're suggesting to use an array. I've got a feeling
however
that I need the original recordset which returns all the titles and
also a second recordset that runs for every single one of the results
to see if there is more than one associated artist and if so to get
the
page to list them.

If a page returns 500 resultant titles then the second recordset would
have to be built 500 times!

Does this make any sense?
Not really.
Just return all the records in a single recordset, sorted by RecordingID.
Use GetRows to stuff the data into an array and make a single pass through
the arraym keeping track of which RecordingID you are on and concatenating
the names when needed. For example, your query returns 4 fields. Add an
Order By clause to it so the records are sorted by RecordingID, open the
recordset and process it as follows:

dim conn, rs, sql, arData, curID, newID, Title, Price, Artists, i

sql="SELECT tblRecordings.R ecordingID,tblA rtists.ArtistNa me, " & _
"tblRecordings. Title, tblRecordings.P rice, FROM tblRecordings " & _
"INNER JOIN " & _
"(tblArtist s INNER JOIN tblLINKArtist_R ecording " & _
"ON tblArtists.Arti stID = tblLINKArtist_R ecording.Artist ID) " & _
"ON tblRecordings.R ecordingID =" & _
"tblLINKArtist_ Recording.Recor dingID " & _
"WHERE tblRecordings. Title Like'%Nobody Told Me%' " & _
"ORDER BY tblRecordings.R ecordingID"
'open conn here, then
Set rs=conn.execute (sql,,1)
If not rs.eof then arData=rs.GetRo ws
rs.close:set rs=nothing
'close and destroy conn here as well, unless you're not finished
'with it ... then:
if isArray(arData) then
curID=arData(0, 0)
Title=arData(2, 0)
Price=arData(3, 0)
for i = 0 to ubound(arData,2 )
newID = arData(0,i)
if newID <curID then
WriteRecord curID,Title,Art ists,Price
curID=newID
Title=arData(2, i)
Price=arData(3, i)
Artists=""
end if
if len(Artists) 0 then
Artists = Artists & ", " & arData(1,0)
else
Artists = arData(1,0)
end if
next
WriteRecord curID,Title,Art ists,Price
else
'handle the no-records situation here
end if

Sub WriteRecord(pID ,pTitle,pArtist s ,pPrice)
'Write the data to the Response
End Sub
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 17 '06 #4
It's becoming clearer now Bob. One more question however. If a
recording does have more than one artist associated with it then the
recording will still be listed more than once. Is there a way to filter
out 'like' recordingIDs like the 'Unique Values' in a query properties
or 'DISTINCT' in SQL might do?

Regards,

Penny

Bob Barrows [MVP] wrote:
an*********@hot mail.com wrote:
Thanks for your response Bob.

I see why you're suggesting to use an array. I've got a feeling
however
that I need the original recordset which returns all the titles and
also a second recordset that runs for every single one of the results
to see if there is more than one associated artist and if so to get
the
page to list them.

If a page returns 500 resultant titles then the second recordset would
have to be built 500 times!

Does this make any sense?
Not really.
Just return all the records in a single recordset, sorted by RecordingID.
Use GetRows to stuff the data into an array and make a single pass through
the arraym keeping track of which RecordingID you are on and concatenating
the names when needed. For example, your query returns 4 fields. Add an
Order By clause to it so the records are sorted by RecordingID, open the
recordset and process it as follows:

dim conn, rs, sql, arData, curID, newID, Title, Price, Artists, i

sql="SELECT tblRecordings.R ecordingID,tblA rtists.ArtistNa me, " & _
"tblRecordings. Title, tblRecordings.P rice, FROM tblRecordings " & _
"INNER JOIN " & _
"(tblArtist s INNER JOIN tblLINKArtist_R ecording " & _
"ON tblArtists.Arti stID = tblLINKArtist_R ecording.Artist ID) " & _
"ON tblRecordings.R ecordingID =" & _
"tblLINKArtist_ Recording.Recor dingID " & _
"WHERE tblRecordings. Title Like'%Nobody Told Me%' " & _
"ORDER BY tblRecordings.R ecordingID"
'open conn here, then
Set rs=conn.execute (sql,,1)
If not rs.eof then arData=rs.GetRo ws
rs.close:set rs=nothing
'close and destroy conn here as well, unless you're not finished
'with it ... then:
if isArray(arData) then
curID=arData(0, 0)
Title=arData(2, 0)
Price=arData(3, 0)
for i = 0 to ubound(arData,2 )
newID = arData(0,i)
if newID <curID then
WriteRecord curID,Title,Art ists,Price
curID=newID
Title=arData(2, i)
Price=arData(3, i)
Artists=""
end if
if len(Artists) 0 then
Artists = Artists & ", " & arData(1,0)
else
Artists = arData(1,0)
end if
next
WriteRecord curID,Title,Art ists,Price
else
'handle the no-records situation here
end if

Sub WriteRecord(pID ,pTitle,pArtist s ,pPrice)
'Write the data to the Response
End Sub
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Aug 17 '06 #5
an*********@hot mail.com wrote:
It's becoming clearer now Bob. One more question however. If
a recording does have more than one artist associated with it
then the recording will still be listed more than once. Is
there a way to filter out 'like' recordingIDs like the 'Unique
Values' in a query properties or 'DISTINCT' in SQL might do?
I see no reason why you could not perform two queries -- one to get a
DISTINCT list of albums and another a DISTINCT list of artists. I certainly
do not hesitate to perform multiple queries when it makes sense to do so.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.
Aug 17 '06 #6
an*********@hot mail.com wrote:
It's becoming clearer now Bob. One more question however. If a
recording does have more than one artist associated with it then the
recording will still be listed more than once.
Actually it won't. The WriteRecord sub only gets called once per
RecordID.
Is there a way to
filter out 'like' recordingIDs like the 'Unique Values' in a query
properties or 'DISTINCT' in SQL might do?
You could (in a separate query), but i see no need in this case.
>
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Aug 17 '06 #7

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

Similar topics

2
8284
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team B
1
1304
by: Colin Steadman | last post by:
I have an ASP site that allows the user to submit an Employee Number to an Oracle procedure. The procedure does some calculations and the results are displayed in the browser. Now, the user would like the ability to submit any number of employee numbers all at once (though not display the results). I think this can be done, but I'm not entirely sure how to
8
4322
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
2
1888
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across the top showing different panels. A DropDownList with a 50+ value/text entries exists on more than one panel but only one will be displayed at a time. Examples might be US states, countries, category codes, etc.
4
2176
by: John Wildes | last post by:
Hello I have a small program that I've created to generate accounting statements out of our policy managment system. The first part of the process is selecting the customer to create the statement for. In this process the application queries the database, returns a dataset of just customer names, and their customer code that is displayed in a list. This results in something like 200 names.
2
2473
by: deja | last post by:
Hello, I am creating an a to z list - basically a count of all results that start with the letter "A", "B", "C" .... and so on. I am pretty poor at SQL so I am sure some brains out there can do better than I have here. What I have is working, I just want to make sure that it is optomized.
7
2234
by: beginner | last post by:
Hi Everyone, I have a simple list reconstruction problem, but I don't really know how to do it. I have a list that looks like this: l= What I want to do is to reorganize it in groups, first by the middle
6
2143
by: barronmo | last post by:
I'm new to programming and even newer to Python and would be grateful for some help on what has been a tough problem for me. The project I am working on is an electronic medical record using MySQL/Python. I'm currrently working on a module that looks up a patient's name based on input from the user. My goal is a lookup based on the first 2 or 3 letters of the patient's last name. The matching results would appear as numbered choices...
5
1082
by: Pat | last post by:
I have written chunks of Python code that look this: new_array = for a in array: if not len( a ): continue new_array.append( a ) and...
0
8440
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
8352
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,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8780
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...
1
8549
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
6189
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...
1
2765
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
2005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1763
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.