title: Can I alias multiple columns? How?
body: <p>I'm using pyodbc and postgres.</p>
  
  <p>Can I alias multiple columns?</p>
  
  <p>Here's the description of my problem:</p>
  
  <p>Data structure:</p>
  
  <pre><code>data
  id | c1  | c2
  -------------
  1  | 11  | 12
  2  | 21  | 22
  </code></pre>
  
  <p>Notation: c is for column</p>
  
  <pre><code>dictionary
  id | key | value
  ----------------
  1  | k1  | v11
  1  | k2  | v12
  2  | k1  | v21
  2  | k2  | v22
  </code></pre>
  
  <p>Notation: k is for key, v is for value</p>
  
  <p>You can think of k1 and k2 as two more columns. The data structure is this way because it's constantly changing. I didn't design it, I just have to go with it.</p>
  
  <p>I can't figure out an sql query to give me something like the following (most importantly, for some row, I can access k1 and k2 columns by some name):</p>
  
  <pre><code>data
  id | c1  | c2  | k1  | k2
  -------------------------
  1  | 11  | 12  | v11 | v12
  2  | 21  | 22  | v21 | v22
  </code></pre>
  
  <p>The problem I keep running into is if I alias the tables, then the sql result will contain two "key" columns from the dictionary table, meaning I can't control which column I access of the two, but if I alias the rows, then I can't control which tables are being referenced inside the sql statement.</p>
  
  <p>The fix I'm thinking is to alias two columns:</p>
  
  <pre><code>SELECT * FROM data
  FULL JOIN dictionary AS a1,a2,a3
  ON data.id = a1
  FULL JOIN dictionary AS a4,a5,a6
  ON data.id = a4
  WHERE a2 = k1 and a5 = k2
  </code></pre>
  
  <p>Notation: a is for alias</p>
  
  <p>The result of this would theoretically look like</p>
  
  <pre><code>data
  id | c1  | c2  | a3  | a6 
  ------------------------- 
  1  | 11  | 12  | v11 | v12
  2  | 21  | 22  | v21 | v22
  </code></pre>
  
  <p>Note all a's would technically be here, but 3 and 6 are the ones I'm interested in</p>