views:

23

answers:

1

i have table with filmname and actors column in sql server 2005

i want the sql query to get all the actors of the film starred by both "bradpitt" and "rusellcrowe"

the table design is as follows

CREATE TABLE [dbo].[mytable](
    [actors ] [nchar](10) NULL,
    [filmname] [nchar](10) NULL,

) ON [PRIMARY]
+2  A: 

get the film where both bradpitt and rusellcrowe (russellcrowe?) exist for that film... which then gives you the actors

SELECT
    actors
FROM
    dbo.MyTable M1
WHERE
    EXISTS (SELECT * FROM
             dbo.MyTable M2
        WHERE
             M2.actors = 'bradpitt' AND M1.filmname. = M2.filmname)
    AND
    EXISTS (SELECT * FROM
             dbo.MyTable M3
        WHERE
             M3.actors = 'rusellcrowe' AND M1.filmname. = M3.filmname)
gbn
+1 @gbn, thanks for pointing that out. I deleted my answer. The key is in the details. :)
Dustin Laine