1

For array = [1,1,1,2], DB table has entry for ids-1,2.

The query -> "SELECT * FROM table WHERE id in array" returns only two rows.

Is there a way where it will return 4 rows instead?

2
  • There is only two rows in the table? Commented Feb 10, 2016 at 14:25
  • If there are only two rows on the table then that's all you will get from that query. Commented Feb 11, 2016 at 9:54

1 Answer 1

0

You can build an in-line table with UNION ALL, then INNER JOIN your table to it:

SELECT t2.*
FROM (
   SELECT 1 AS v UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 2
) AS t1
INNER JOIN mytable AS t2 ON t1.v = t2.id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.