SQL Query help

R

rob willaar

Could someone help me with a query?
I have a table with the fields actor1,actor2,actor3 and i like to have a
list of all actors starting 'nicola%' from those fields with no duplicate
names. How can i do it with an sql query?
 
S

Sasidhar

If I understood your question properly then this is the simplest way to do
this is

SELECT DISTINCT ACTOR
FROM
(
SELECT ACTOR1 AS ACTOR
FROM TABLENAME
WHERE ACTOR1 LIKE 'nicola%'
UNION
SELECT ACTOR2 AS ACTOR
FROM TABLENAME
WHERE ACTOR2 LIKE 'nicola%'
UNION
SELECT ACTOR3 AS ACTOR
FROM TABLENAME
WHERE ACTOR3 LIKE 'nicola%'
) AS ACTORS
 
B

Ben

UNION returns distinct results by default.

Sasidhar said:
If I understood your question properly then this is the simplest way to do
this is

SELECT DISTINCT ACTOR
FROM
(
SELECT ACTOR1 AS ACTOR
FROM TABLENAME
WHERE ACTOR1 LIKE 'nicola%'
UNION
SELECT ACTOR2 AS ACTOR
FROM TABLENAME
WHERE ACTOR2 LIKE 'nicola%'
UNION
SELECT ACTOR3 AS ACTOR
FROM TABLENAME
WHERE ACTOR3 LIKE 'nicola%'
) AS ACTORS
 
R

rob willaar

Perfect!
Tnx a lot!

Learning all the time...

Sasidhar said:
If I understood your question properly then this is the simplest way to do
this is

SELECT DISTINCT ACTOR
FROM
(
SELECT ACTOR1 AS ACTOR
FROM TABLENAME
WHERE ACTOR1 LIKE 'nicola%'
UNION
SELECT ACTOR2 AS ACTOR
FROM TABLENAME
WHERE ACTOR2 LIKE 'nicola%'
UNION
SELECT ACTOR3 AS ACTOR
FROM TABLENAME
WHERE ACTOR3 LIKE 'nicola%'
) AS ACTORS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top