let's see I have a simple table
like this:
name id
tom 1
jerry 2
... ...
And from the outside, I got a list contains the names (tom, jerry, kettie...)
I am trying to use WHERE IN
clause to retrieve the id based on the name list.
I can do
SELECT id FROM mySimpleTable where name in ('tom','jerry','kettie');
So just iterate the name list
and generate the contents in the parentheses.
This works, but the results is not in the input order, for example, the input is tom, jerry, kettie
, the expected the result is 1,2,3
, however, the output actually could be in any order.
Then how can I modify the SQL clause
to make sure I get my input and output matched so that I can do the following process accrordingly. I heard JOIN
may help in this situation.