How to get all rows using duplicate value in IN

0

How do I get all rows using IN (), and inside the IN () have duplicate values

SELECT NOME FROM PESSOA WHERE ID IN (1,1,1,2,3,3,4)

I want to return 3 times the name of ID 1, and 2 times the name of ID 3.

    
asked by anonymous 29.10.2014 / 15:11

1 answer

1

I found a way, more complex, but I think it's the way

SELECT NOME FROM PESSOA WHERE ID = 1
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 1
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 1
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 2
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 3
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 3
UNION ALL
SELECT NOME FROM PESSOA WHERE ID = 4

I can do a script to generate SQL based on the values of IN so it will not be very difficult, just work really ...

    
29.10.2014 / 15:41