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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 query help

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2011-12-01 : 10:10:25
Hi friends,

The tables are:

MovieInventory
This table contains one row per movie. Each row contains the name of the movie (movie_title), the price a subscriber needs to pay if he loses or damages the movie (replacement_price), and the number of movies currently in inventory (onhand_qty), a value of zero means we are out of stock. The primary key is movie_title.
NotFlix
This table describes the queues of movies that need to be sent to each subscriber. It contains one row per movie in a queue to be sent to a subscriber. Each row has the name of the subscriber (subscriber_name), the position of the movie in the queue (queue_nbr), and the name of the movie (movie_title). Position one is the first movie to be sent to the subscriber, position two is the next movie, etc. The primary key is made up of subscriber_name and queue_nbr. The foreign key to the MovieInventory table is movie_title.

Question:

Write a query that produces the names of all subscribers who ordered the same movie more than once. Have the query output only the names, nothing else. Do not repeat names even if a subscriber ordered several movies more than once.


Can someone check my answer:
select distinct subscriber_name
from ( select subscriber_name from NOTFlix
group by movie_title having count(*) >1)


thank you


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-01 : 10:13:45
it should be

select distinct subscriber_name
from NOTFlix
group by subscriber_name,movie_title
having count(*) >1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -