473,324 Members | 2,567 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.

Insert into a table fields from another table based on a field

Hi All

I have 2 tables (as shown below), if i add a row to the FILES TABLE then the myid value is added to mydata list in the PLAYLISTS TABLE, based on the genre matching the myname values.
Hope this makes sense.
So my question is how do i add myid to mydata when new files are added to the FILES TABLE.
Thanks

FILES TABLE
filepath.........artist..............album.....gen re.......myid
c:/files..........u2..................war........Rock ........1234
c:/files..........u2..................war........Rock ........1235
c:/files..........u2..................war........Rock ........1236
c:/files..........madonna........hits........Rock.... ....1237


PLAYLISTS TABLE
myname.......user........mydata
Rock............admin.....1234,1235,1236
Pop..............admin.....1237
Oct 28 '07 #1
2 1641
bartonc
6,596 Expert 4TB
The mydata column in a no-no (non-atomic data is impossible to normalize).

Just my two cents worth...
Oct 28 '07 #2
pbmods
5,821 Expert 4TB
Heya. MrCrunchy. Welcome to TSDN!

Try this structure:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE
  2.     `files`
  3.     (
  4.         `fileid`
  5.             BIGINT(20)
  6.             UNSIGNED
  7.             NOT NULL
  8.             AUTO_INCREMENT,
  9.         `albumid`
  10.             BIGINT(20)
  11.             UNSIGNED
  12.             NOT NULL,
  13.         `genreid`
  14.             BIGINT(20)
  15.             UNSIGNED
  16.             NOT NULL,
  17.         `path`
  18.             VARCHAR(100)
  19.             NAT NULL,
  20.  
  21.         PRIMARY KEY
  22.             (`fileid`),
  23.         KEY
  24.             `artist`
  25.             (`artistid`),
  26.         KEY
  27.             `album`
  28.             (`albumid`),
  29.         KEY
  30.             `genre`
  31.             (`genreid`)
  32.     );
  33.  
  34. CREATE TABLE
  35.     `artists`
  36.     (
  37.         `artistid`
  38.             BIGINT(20)
  39.             UNSIGNED
  40.             NOT NULL
  41.             AUTO_INCREMENT,
  42.         `name`
  43.             VARCHAR(50)
  44.             NOT NULL,
  45.  
  46.         PRIMARY KEY
  47.             (`artistid`)
  48.     );
  49.  
  50. CREATE TABLE
  51.     `albums`
  52.     (
  53.         `albumid`
  54.             BIGINT(20)
  55.             UNSIGNED
  56.             NOT NULL
  57.             AUTO_INCREMENT,
  58.         `name`
  59.             VARCHAR(50)
  60.             NOT NULL,
  61.         `releaseYear`
  62.             SMALLINT(4)
  63.             UNSIGNED
  64.             NOT NULL,
  65.  
  66.         PRIMARY KEY
  67.             (`albumid`),
  68.         KEY
  69.             `releaseYear`
  70.             (`releaseYear`)
  71.     );
  72.  
  73. CREATE TABLE
  74.     `map_album_artist`
  75.     (
  76.         `albumid`
  77.             BIGINT(20)
  78.             UNSIGNED
  79.             NOT NULL,
  80.         `artistid`
  81.             BIGINT(20)
  82.             UNSIGNED
  83.             NOT NULL,
  84.  
  85.         PRIMARY KEY
  86.         (
  87.             `albumid`,
  88.             `artistid`
  89.         ),
  90.         KEY
  91.             `artist`
  92.             (`artistid`)
  93.     );
  94.  
  95. CREATE TABLE
  96.     `genres`
  97.     (
  98.         `genreid`
  99.             BIGINT(20)
  100.             UNSIGNED
  101.             NOT NULL,
  102.         `name`
  103.             VARCHAR(50),
  104.  
  105.         PRIMARY KEY
  106.             (`genreid`),
  107.         UNIQUE KEY
  108.             `name`
  109.             (`name`)
  110.     );
  111.  
  112. CREATE TABLE
  113.     `users`
  114.     (
  115.         `userid`
  116.             BIGINT(20)
  117.             UNSIGNED
  118.             NOT NULL,
  119.         `username`
  120.             VARCHAR(50)
  121.             NOT NULL,
  122.         -- You probably have some other columns that go in this table.
  123.  
  124.         PRIMARY KEY
  125.             (`userid`),
  126.         UNIQUE KEY
  127.             `username`
  128.             (`username`)
  129.     );
  130.  
  131. CREATE TABLE
  132.     `playlists`
  133.     (
  134.         `playlistid`
  135.             BIGINT(20)
  136.             UNSIGNED
  137.             NOT NULL,
  138.         `name`
  139.             VARCHAR(50)
  140.             NOT NULL,
  141.  
  142.         PRIMARY KEY
  143.             (`playlistid`),
  144.         KEY
  145.             `name`
  146.             (`name`)
  147.     );
  148.  
  149. CREATE TABLE
  150.     `map_playlist_file`
  151.     (
  152.         `playlistid`
  153.             BIGINT(20)
  154.             UNSIGNED
  155.             NOT NULL,
  156.         `fileid`
  157.             BIGINT(20)
  158.             UNSIGNED
  159.             NOT NULL,
  160.  
  161.         PRIMARY KEY
  162.             (`playlistid`),
  163.         KEY
  164.             `file`
  165.             (`fileid`)
  166.     );
  167.  
  168. CREATE TABLE
  169.     `map_playlist_user`
  170.     (
  171.         `playlistid`
  172.             BIGINT(20)
  173.             UNSIGNED
  174.             NOT NULL,
  175.         `userid`
  176.             BIGINT(20)
  177.             UNSIGNED
  178.             NOT NULL,
  179.  
  180.         PRIMARY KEY
  181.         (
  182.             `playlistid`,
  183.             `userid`
  184.         ),
  185.         KEY
  186.             `user`
  187.             (`userid`)
  188.     );
  189.  
Oct 28 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: shank | last post by:
I have a recordset that contains multiple records of product a user is purchasing. For clarity, I converted the recordset fields to variables. I need to take that entire recordset and insert it...
1
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
2
by: Bill | last post by:
I'm having what seems to me to be an odd problem. Perhaps there is some explanation, but don't know at this point. Basically I have a form that tracks memberships and donations. The main form...
5
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
1
by: elfyn | last post by:
I'm currently building a DB that you will keep track of vehicles, services to the vehicles and parts used for the servicing of the vehicles. I've created a table for Customers, Vehicles and...
8
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
13
by: shookim | last post by:
I don't care how one suggests I do it, but I've been searching for days on how to implement this concept. I'm trying to use some kind of grid control (doesn't have to be a grid control, whatever...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
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...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
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.