1

I have following SQL query -

SELECT * FROM users where id=X

Here 'X' is the set of values which need to be read from a file say ~/ids.lst. I have following approach in hand.

  1. Read ids.lst and load all variables.
  2. For each variable form and fire an SQL query and concat the results.

I have working code in python, but the problem is if I have n ids, then n queries will be made to server. Is there any way I could achieve the same with a single query to server?

2
  • Show us the code then we can help you Commented Nov 4, 2014 at 6:43
  • I can't! My query is not exactly what I mentioned above. It is a code which I can't make public, but with the algo above, the motive should be well understood! Commented Nov 4, 2014 at 6:47

1 Answer 1

3

You can use in operator for single query.

SELECT * FROM users where id in (<concat ids with , (comma) read from file.>)

This will be single query and faster compare to individual query.

Sign up to request clarification or add additional context in comments.

1 Comment

Aweseome! It is exactly what I was looking for.

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.