1

I want to execute a sqlite query:

select * from table_name where id in (23,33,33,55,43,23);

if any value is appearing in the array twice, cursor should contain the corresponding row twice.

7
  • what r u getting ? single row? Commented Jun 12, 2014 at 5:13
  • try to get distinct data from table. Commented Jun 12, 2014 at 5:14
  • Or should i just run the query in a for loop? Commented Jun 12, 2014 at 5:16
  • I am getting each row only one time. The array contains same id twice. So i want that row shown in the cursor two times. Commented Jun 12, 2014 at 5:21
  • 1
    It will only check the row's someID against the values of the IN(). It doesn't matter how your IN() looks like, it will not return more results than there are rows that matches that value Commented Jun 12, 2014 at 5:53

1 Answer 1

1

Yes run a for loop or use a join:

SELECT T.*
FROM (
  SELECT 23 AS id
  UNION SELECT 33
  ...
  UNION SELECT 23) AS list
LEFT JOIN table_name T ON list.id = T.id

Based on this answer https://stackoverflow.com/a/372991/360211

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.