subash
subash

Reputation: 4137

sql query to get the sql server 2005

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]

Upvotes: 0

Views: 47

Answers (1)

gbn
gbn

Reputation: 432180

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)

Upvotes: 2

Related Questions