Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help Complicated Updates

Author  Topic 

ricom19
Starting Member

4 Posts

Posted - 2007-06-16 : 07:17:06
Hello guys,
I am askng for any help ...am trying to get this SQL language.

I want to provide an SQL query to set all the priority to 1 for all customers that have all their orders being for a product with importance of 100.
--------------------------------------------------------------------
There are three tables in the database: Customer, Product and Orders.

The Customer table has three column: Customer_id (PK), priority, Address.

The Orders table has three colums as well: Order_id (PK), Customer_id (FK), Product_id (FK)

The Product table has three columns as well: Product_id(PK), Product_name, Importance.

So the order table is connected to both the product and the customers table by respective foreign key.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-16 : 08:23:00
[code]
update c
set priority = 1
from customer c inner join orders o
on c.customer_id = o.customer_id
inner join product p
on o.product_id = p.product_id
where importance = 100
[/code]


KH

Go to Top of Page

ricom19
Starting Member

4 Posts

Posted - 2007-06-16 : 08:51:01
Thats was what i originally thought...thank you though. However, based on what i understand from SQL so far...that query would set priority 1 to all customers who has at least one order with a product with an importance of 100. What i want is a query that only sets priority 1 to customers who have all there orders being only products of importance of 100.

please if am misunderstanding don't hesitate to point that out and then send me in the right direction.
Go to Top of Page
   

- Advertisement -