gphatch
Materials
- Jan 31, 2003
- 45
Hi there - it's been so long since I did a SQL query that I've forgot what I need to do here...
I have three tables in an MS Access database:
1) "Name" with columns "NameID" and "Name".
2) "Category" with columns "CategoryID", "Category" and "Added?".
3) "Link" with columns "LinkID", "NameID" and "CategoryID".
The NameID and CategoryID items in the Link table are tied to those respective items in the other two tables.
So here's what I need to do with this data:
1) There are some duplicate names in the "Name" Table. This is because the same name may appear in different Categories. However, I really only want to have a single instance of any name, in the Names table. I need to run a query that will discover which names have duplicates, and then go in and replace the NameID-CategoryID link pairs in the Link table, with pairs that contain on one NameID in each instance. I would then want to delete the duplicate Name records in the Name table.
For example, The name Bob might appear three times in the Names table, with NameIDs of 1, 2 and 3. There might be three categories in the Category table that the name "Bob" is associated with, with CategoryIDs of 5, 6 and 7. So currently in the Links table [in this example], there would be Link pairs of 1-5, 2-6 and 3-7. I want to replace these pairs with 1-5, 1-6 and 1-7, and delete the records 2 and 3 in the Names table.
What's the easiest way to do this using SQL?
2) Once I've done all that - what's the easiest way to query the DB to produce:
a) A report / output that lists how many names there are in each category and
b) creates a report / output that lists all the names in alphabetical order, grouped by Category name but ONLY if the Category has at least 1 name associated with it?
THANKS in advance for any help!! I plan to use SQL in either ASP or CFML to generate this stuff, but if it's easier to do it directly in MS Access [rather than just using the DM as a datasource], I'd appreciate pointers on that too!
I have three tables in an MS Access database:
1) "Name" with columns "NameID" and "Name".
2) "Category" with columns "CategoryID", "Category" and "Added?".
3) "Link" with columns "LinkID", "NameID" and "CategoryID".
The NameID and CategoryID items in the Link table are tied to those respective items in the other two tables.
So here's what I need to do with this data:
1) There are some duplicate names in the "Name" Table. This is because the same name may appear in different Categories. However, I really only want to have a single instance of any name, in the Names table. I need to run a query that will discover which names have duplicates, and then go in and replace the NameID-CategoryID link pairs in the Link table, with pairs that contain on one NameID in each instance. I would then want to delete the duplicate Name records in the Name table.
For example, The name Bob might appear three times in the Names table, with NameIDs of 1, 2 and 3. There might be three categories in the Category table that the name "Bob" is associated with, with CategoryIDs of 5, 6 and 7. So currently in the Links table [in this example], there would be Link pairs of 1-5, 2-6 and 3-7. I want to replace these pairs with 1-5, 1-6 and 1-7, and delete the records 2 and 3 in the Names table.
What's the easiest way to do this using SQL?
2) Once I've done all that - what's the easiest way to query the DB to produce:
a) A report / output that lists how many names there are in each category and
b) creates a report / output that lists all the names in alphabetical order, grouped by Category name but ONLY if the Category has at least 1 name associated with it?
THANKS in advance for any help!! I plan to use SQL in either ASP or CFML to generate this stuff, but if it's easier to do it directly in MS Access [rather than just using the DM as a datasource], I'd appreciate pointers on that too!