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

How to Compare All Rows of TBL_1 All Rows of TBL_2?

All,

I need a little help understanding which concepts / functions /
methods / strategies I should use to accomplish what I'll describe
below. Note - the real implementation isn't about music - I just
thought it would be easier to understand, if not more fun to think
about.

I have a table with 8,000 rows. Let's call that the "TBL_Fav_Songs"
table. It contains a list of my favorite songs, in the column |
MyFavs|.

I have a table with 117,000 rows. Let's call that the
"TBL_All_Albums" table. It contains a list of albums in my music
library. The table has three columns - |Album|Songs|FavSongs|

|Album| contains the Album name.
|Songs| contains the songs on an album, in a text field - all songs
listed together in one field.
|FavSongs is empty at the moment.

I want to wind up with a table in which FavSongs is populated with the
names of songs that are my favorites, for each album listed.

I need to search the |Songs| field of the "Albums" table, for matches
from the songs listed in the |MyFavs| column in the "TBL_Fav_Songs"
table.

Wherever I find a match, I want to populate the |FavSongs| field.
There can be multiple matches per album, and a song can be on multiple
albums ($%^& annviersary reissues!).

I think I'm going to need to use nested loops, and have a routine that
fills in the |FavSongs| field, appending new values to the field as it
finds matches. I guess I don't know whether to search one row in the
"TBL_All_Albums" table for matches to every row in the "TBL_Fav_Songs"
table, or to search all of the rows in the "TBL_All_Albums" table for
matches to one row in the "TBL_Fav_Songs" table.

Suggestions, including a good resource for learning how to do this?

Thanks,

Patrick
Jul 21 '08 #1
5 1263
Hi Patrick,

On Jul 21, 10:29 pm, Patrick A <park...@stradley.comwrote:
I have a table with 8,000 rows. Let's call that the "TBL_Fav_Songs"
table. It contains a list of my favorite songs, in the column |
MyFavs|.

I have a table with 117,000 rows. Let's call that the
"TBL_All_Albums" table. It contains a list of albums in my music
library. The table has three columns - |Album|Songs|FavSongs|

|Album| contains the Album name.
|Songs| contains the songs on an album, in a text field - all songs
listed together in one field.
|FavSongs is empty at the moment.

I want to wind up with a table in which FavSongs is populated with the
names of songs that are my favorites, for each album listed.
I would copy TBL_All_Albums into a table with a different structure
such as
TBL_All_Albums_Revised with three columns - |Album|Song|IsFav|

Then I could set the IsFav flag by running a simple SQL query such as
UPDATE TBL_All_Albums_Revised
SET IsFav = TRUE
WHERE Song = ANY(
SELECT MyFavs
FROM TBL_Fav_Songs);

For a database to work well, each entry in column Song should contain,
not a list of songs, but a single song.
Hope that helps,

Chris
Jul 21 '08 #2
Try something like the following query which would update TBL_All_Albums
by setting the FavSongs column equal to the FavSongs column in
TBL_Fav_Songs. So for every row that contains a song in the Song column
which matches a FavSong, the first FavSong column would get the matching
FavSong from the 2nd table.

UPDATE TBL_All_Albums t1 INNER JOIN TBL_Fav_Songs t2 ON t1.Song =
t2.FavSong SET t1.FavSong = t2.FavSong
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 21 '08 #3
Hi Rich,
So for every row that contains a song in the Song column
which matches a FavSong, the first FavSong column would get the matching
FavSong from the 2nd table.

UPDATE TBL_All_Albums t1 INNER JOIN TBL_Fav_Songs t2 ON t1.Song =
t2.FavSong SET t1.FavSong = t2.FavSong
Your SQL is fine but Patrick A writes:
"|Songs| contains the songs on an album, in a text field - all songs
listed together in one field."
so the SQL will result in zero updates.

Once he gets the structure right, your SQL will do the heavy lifting
for him.

Just my thoughts,

Chris
Jul 22 '08 #4
Rich, Chris,

Thanks for trying to help.

Two issues:

1. I cannot change the structure of the database.
2. Knowing if an album has a favorite is not sufficient. The result I
need is to have the favorite (or favorites - there can be multiples)
written to the |FavSongs| field in the TBL_All_Albums.

I'll keep digging...

Patrick
Jul 22 '08 #5
On Jul 22, 2:37 pm, Patrick A <park...@stradley.comwrote:
Two issues:

1. I cannot change the structure of the database.
2. Knowing if an album has a favorite is not sufficient. The result I
need is to have the favorite (or favorites - there can be multiples)
written to the |FavSongs| field in the TBL_All_Albums.
In that case, you will need to use some VBA code and, as you
predicted, nested loops. I'm sure we can help with that.

I would scan the larger table and compare each song with the list of
favourites. How are you separating each of the songs in the Songs
field?

Chris
Jul 22 '08 #6

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

Similar topics

4
by: Gleep | last post by:
Hey Guys, I've got a table called Outcomes. With 3 columns and 15 rows 1st col 2nd col 3rdcol outcome date price There are 15 rows...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
9
by: geronimo_me | last post by:
Hi, I am atempting to compare part of a field with the whole of another field in access. Is this possible? Basically I have 2 tables with the following info: Table1 Field1 = MR.
9
by: VMI | last post by:
I have two tables and I want to compare these two tables with a query( ie. "select * from A where B.key = A.key") and the result will be stored in a 3rd table (table C). is this possible? If...
5
by: rcolby | last post by:
Evening, Wondering if someone can point me in the right direction, on how I would compare a system.guid with a system.byte. system.guid (pulled from sql server table with a data type of...
4
by: Justin Emlay | last post by:
I have two lists. These can be in either table form or array. That is, my data is in a dataset which I can move to an array if need be. ListA is a master list and it contains all items. ListB...
1
by: adeelanjum2001 | last post by:
I have two datatables with same structure. i want to compare the values in each row. for example: datatable1.rows(0).item(0) = datatable2.rows(0).item(0) one way to compare the rows in datatable...
13
by: Shelley | last post by:
Compare Current Year Worksheet with Previous Year Worksheet and if SSN exists in Current Year Worksheet & Not in Previous Year - Copy this Row from Current Year Worksheet & Paste into Previous Year...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.