MYSQL, How do SELECT without grouping identical WHERE values?

Asked

Viewed 74 times

1

Good Afternoon

SELECT id, descricao FROM Produtos WHERE id IN ('1','1','2', '3','3');

But the result is

id / descricao
1 / Caneta
2 / Lapis
3 / Borracha

I wanted it to be according to the table below

id / descricao
1 / Caneta
1 / Caneta
2 / Lapis
3 / Borracha
3 / Borracha
  • you will use this feedback with some language? I believe it is easier to do it there...

  • I’m not sure if it works, but I think you can create a list type variable, fill in the values of the "IN" clause and use a "WHILE" to select on top of each of the items.

1 answer

0


Hey there, buddy boy! I believe you need to use UNION and structure your SELECT as an example below:

Mysql Instruction

SELECT id, descricao FROM Produtos WHERE id IN (1) UNION
SELECT id, descricao FROM Produtos WHERE id IN (1)

This will cause SELECT to be performed individually and unified when running.

I believe this is an alternative.
I hope I’ve helped.

Hugs,

Browser other questions tagged

You are not signed in. Login or sign up in order to post.