Do this instead<br><br>cur.execute(&#39;select * from Employee where id in (%s)&#39;, ids.join(&#39;, &#39;));<br><br><div class="gmail_quote">On Wed, Dec 17, 2008 at 5:13 PM, Vijay Ramachandran <span dir="ltr">&lt;<a href="mailto:vijay750@gmail.com">vijay750@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello.<br><br>I&#39;m unable to figure out how to use mysqldb (actually, dbabi) to write an &quot;in&quot; query.<br>
<br>For instance, suppose my table looks like this:<br>Employee(<br>&nbsp;id int not null primary key,<br>&nbsp;name varchar(32) not null)<br>

);<br><br>Suppose I have a list of ids, I would write sql such as<br>&#39;select * from Employee where id in (id1, id2, id3)&#39; and this would work even if there was only one id, say, &#39;select * from Employee where id in (id1)&#39;<br>

<br>How should I do this in MySQLdb? It seems that I need to handle single entry list differently from a list with multiple elements? i.e., this code below works:<br><br><br>ids = [1, 2, 3]<br>if len(ids) &gt; 1:<br>&nbsp;&nbsp;&nbsp; cur.execute(&#39;select * from Employee where id in %s&#39;, tuple(ids))<br>

else:<br>&nbsp;&nbsp;&nbsp; cur.execute(&#39;select * from Employee where id = %s&#39;, ids[0])<br><br>but it doesn&#39;t seem right. What&#39;s the correct way to run this query?<br><br>thanks,<br><font color="#888888">Vijay<br>
</font><br>_______________________________________________<br>
BangPypers mailing list<br>
<a href="mailto:BangPypers@python.org">BangPypers@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/bangpypers" target="_blank">http://mail.python.org/mailman/listinfo/bangpypers</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>I am but a man.<br>