Hi everyone:
In one of my interview, I got this question:
Table Actress
--------------
Actress_id First_name last_name
1 Britney Spears
2 Jennifer Lopez
3 Kelly Clarkson
I need a query to display these:
Britney Spears
Clarkson, Kelly
Jennifer Lopez
Kelly Clarkson
Lopez, Jennifer
Spears, Britney
In another word: I need to display all the names in two different formats: <first name> <last name> and <last name>, <first name> and sort them
I come up with this solution:
SELECT First_name, last_name from Actress
UNION
SELECT concat(last_name, ','), First_name from Actress
ORDER BY 1
But I was told that this query is not efficient, and there is a better way to do that.
Could anyone help?
Thanks so much -)
Sugi
In one of my interview, I got this question:
Table Actress
--------------
Actress_id First_name last_name
1 Britney Spears
2 Jennifer Lopez
3 Kelly Clarkson
I need a query to display these:
Britney Spears
Clarkson, Kelly
Jennifer Lopez
Kelly Clarkson
Lopez, Jennifer
Spears, Britney
In another word: I need to display all the names in two different formats: <first name> <last name> and <last name>, <first name> and sort them
I come up with this solution:
SELECT First_name, last_name from Actress
UNION
SELECT concat(last_name, ','), First_name from Actress
ORDER BY 1
But I was told that this query is not efficient, and there is a better way to do that.
Could anyone help?
Thanks so much -)
Sugi