PDA

View Full Version : Adding new content to a table by refering other tables using SQL


sujith
01-05-2007, 10:58 AM
I keep product name, id in Table1.
I keep Category name, id in Table2.
I keep relation between product and category (product_id, category_id) in Table3.
I have added some products to the table with proper category.
Work fine
But for some products I did not specified any category
(ie their id is not present in Table3)
But now I want all such products
(ie all products whose category is nothing)
To be associated with category_id 10

Can I do this simply with SQL queries?

Hope u can help me

sujithukvl@gmail.com

sujith
01-06-2007, 08:01 AM
I keep product name, id in Table1.
I keep Category name, id in Table2.
I keep relation between product and category (product_id, category_id) in Table3.
I have added some products to the table with proper category.
Work fine
But for some products I did not specified any category
(ie their id is not present in Table3)
But now I want all such products
(ie all products whose category is nothing)
To be associated with category_id 10

Can I do this simply with SQL queries?

Hope u can help me






sujithukvl@gmail.com

ie I want to insert all product_id to table3 if they are not present in table 3

guelphdad
01-06-2007, 08:05 PM
you can do that. what you would need to do first is find out what the products are that are not assigned to any category.

show us how you would do that in a join or subquery and we can help you with the next part of the problem.

sujith
01-08-2007, 02:23 PM
Really the following querry selects all productID s and their category even if category is null

SELECT Product.productID, ProductCategoryAssociation.categoryID FROM Product LEFT JOIN ProductCategoryAssociation ON Product.ProductID =ProductCategoryAssociation.ProductID
.............

OR according to my post table names are following

SELECT Table1.productID, Table3.categoryID FROM Table1 LEFT JOIN table3 ON Table1.ProductID =table3.ProductID