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

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_Recording 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.ArtistName, tblRecordings.RecordingID,
tblRecordings.Title, tblRecordings.Price, FROM tblRecordings INNER JOIN
(tblArtists INNER JOIN tblLINKArtist_Recording ON tblArtists.ArtistID =
tblLINKArtist_Recording.ArtistID) ON tblRecordings.RecordingID =
tblLINKArtist_Recording.RecordingID
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 1384
an*********@hotmail.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*********@hotmail.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*********@hotmail.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.RecordingID,tblArtists.ArtistName, " & _
"tblRecordings.Title, tblRecordings.Price, FROM tblRecordings " & _
"INNER JOIN " & _
"(tblArtists INNER JOIN tblLINKArtist_Recording " & _
"ON tblArtists.ArtistID = tblLINKArtist_Recording.ArtistID) " & _
"ON tblRecordings.RecordingID =" & _
"tblLINKArtist_Recording.RecordingID " & _
"WHERE tblRecordings. Title Like'%Nobody Told Me%' " & _
"ORDER BY tblRecordings.RecordingID"
'open conn here, then
Set rs=conn.execute(sql,,1)
If not rs.eof then arData=rs.GetRows
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,Artists,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,Artists,Price
else
'handle the no-records situation here
end if

Sub WriteRecord(pID,pTitle,pArtists ,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*********@hotmail.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.RecordingID,tblArtists.ArtistName, " & _
"tblRecordings.Title, tblRecordings.Price, FROM tblRecordings " & _
"INNER JOIN " & _
"(tblArtists INNER JOIN tblLINKArtist_Recording " & _
"ON tblArtists.ArtistID = tblLINKArtist_Recording.ArtistID) " & _
"ON tblRecordings.RecordingID =" & _
"tblLINKArtist_Recording.RecordingID " & _
"WHERE tblRecordings. Title Like'%Nobody Told Me%' " & _
"ORDER BY tblRecordings.RecordingID"
'open conn here, then
Set rs=conn.execute(sql,,1)
If not rs.eof then arData=rs.GetRows
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,Artists,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,Artists,Price
else
'handle the no-records situation here
end if

Sub WriteRecord(pID,pTitle,pArtists ,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*********@hotmail.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*********@hotmail.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
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...
1
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...
8
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. ...
2
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...
4
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...
2
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...
7
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,...
6
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...
5
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.