What I am trying to do is to get the same column result twice with a single query.
SELECT appellation FROM persona WHERE character_id IN (853,12,853) ORDER BY FIELD(character_id,853,12,853)
This returns the result:
character_id | appellation
---------------------------
853 | John Cena
12 | Chris Brown
But what I am looking for to return is:
character_id | appellation
---------------------------
853 | John Cena
12 | Chris Brown
853 | John Cena
Is there a way in MySQL to get that result?
2
Answers
You can achieve this result using
UNION
:It seems strange that you want the same row twice though…
To do this, you can provide a values table and join persona from it:
(left join if you want rows even if there’s no matching persona)
The
select...where 0
is just to give the column a meaningful name.fiddle
Note that you will not necessarily get them in the order specified in the list; to do that you need to provide something to order on: