title: Getting Table and Column names in PyOdbc
body: <p>I'd like to retrieve the fully referenced column name from a PyOdbc Cursor.  For example, say I have 2 simple tables:</p>
  
  <ul>
  <li><code>Table_1(Id, &lt; some other fields &gt;)</code></li>
  <li><code>Table_2(Id, &lt; some other fields &gt;)</code></li>
  </ul>
  
  <p>and I want to retrieve the joined data</p>
  
  <pre><code>select * from Table_1 t1, Table2 t2 where t1.Id = t2.Id
  </code></pre>
  
  <p>using pyodbc, like this:</p>
  
  <pre><code>query = 'select * from Table_1 t1, Table2 t2 where t1.Id = t2.Id'
  
  import pyodbc
  conn_string = '&lt;removed&gt;'
  connection =  pyodbc.connect(conn_string)
  
  cursor = connection.cursor()cursor.execute(query)
  </code></pre>
  
  <p>I then want to get the column names:</p>
  
  <pre><code>for row in cursor.description:
      print row[0]
  </code></pre>
  
  <p>BUT if I do this I'll get <code>Id</code> twice which I don't want.  Ideally I could get <code>t1.Id</code> and <code>t2.Id</code> in the output.</p>
  
  <p>Some of the solutions I've thought of (and why I don't really want to implement them):</p>
  
  <ol>
  <li>re-name the columns in the query - in my real-world use case there are dozens of tables, some with dozens of rows that are changed far too often</li>
  <li>parse my query and automate my SQL query generation (basically checking the query for tables, using the cursor.tables function to get the columns and then replacing the <code>select *</code> with a set of named columns) - If I have too I'll do this, but it seems like overkill for a testing harness</li>
  </ol>
  
  <p>Is there a better way?  Any advice would be appreciated.</p>