select data from table where name = list?
<p>Let's say I have a table names like this :</p>

<pre><code>cust_id    cust_name
   1         John
   2         Mary
   3         Pete
</code></pre>

<p>and I create a list of customers and orders in python like this :</p>

<pre><code>{'Pete','pen','Mary','apple','Pete','pencil','John','shirt','John','watch','Mary','sandal'}
</code></pre>

<p>how do I get the <code>cust_id</code> from the table above where the name is like on the list so that a new table will be like this?</p>

<pre><code>id_order    cust_id    orders  
   1           3        pen
   2           2       apple
   3           3       pencil
   4           1       shirt
   5           1       watch
   6           2       sandal
</code></pre>

<p>so the main point of my question how do i select <code>cust_id</code> in the order of my python customer list? and insert them to a new table of order above?</p>

<p>I am assuming all the required columns are already present in your current table say <code>MY_TABLE</code>. Your SQL query should be like:</p>

<pre><code>SELECT id_order, cust_id, orders from  MY_TABLE where cust_name IN ('Pete', 'Mary', 'John');
</code></pre>

<p>Columns I am expecting in "MY_TABLE":</p>

<ul>
<li>id_order</li>
<li>cust_id</li>
<li>orders</li>
<li>cust_name</li>
</ul>

python mysql