0

I am trying to select from a table where values of one of the columns is equal to values of a list. For example:

TABLE
------------
ID    price
a     100
b     200
...
z     2600

python list: ["a", "d" , "e"]. And i want to find the prices of each of those IDs. The obvious way of doing this is to do a JOIN on ID but that list is not a table. what should i do?

WindowsMaker
  • 3,132
  • 7
  • 29
  • 46

1 Answers1

3

You could write the list to a temporary table, and join with that. To make the join more efficient, ensure that at least one of the join columns (preferrably that of the smaller table) is indexed.

However, if the list is not too long, you can simply use the IN operator:

SELECT *
FROM MyTable
WHERE ID IN ('a', 'd', 'e')
CL.
  • 173,858
  • 17
  • 217
  • 259