A
A
Anton Neverov2016-04-14 17:30:24
PHP
Anton Neverov, 2016-04-14 17:30:24

How to display duplicate rows in a MySQL query "WHERE IN (1,2,3)"?

Hello!
There was such a situation:
there is a request to the database:
"SELECT * FROM $table WHERE id IN $id"
where $id = (1,2,2,3)
The base returns only 3 rows (since "2" is repeated), and I need all 4. Ie. repeating lines must also be taken again and subsequently displayed. How is it possible to implement it?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vdem, 2016-04-14
@TTATPuOT

Means SQL IMHO in any way. Do post-processing of the query result. On the returned records, build a key-value structure (with id as the key), then go through all the ids from IN() and for each get a record from the structure by key and add it to the result array.

D
DarkMatter, 2016-04-14
@darkmatter

So it displays by id and id is usually the primary key, which means it can only be 1 in the database. If you have 2 identical id in the database, then something is wrong in it...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question