Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:06:52+00:00 2026-06-06T20:06:52+00:00

I’m using pyodbc and postgres. Can I alias multiple columns? Here’s the description of

  • 0

I’m using pyodbc and postgres.

Can I alias multiple columns?

Here’s the description of my problem:

Data structure:

data
id | c1  | c2
-------------
1  | 11  | 12
2  | 21  | 22

Notation: c is for column

dictionary
id | key | value
----------------
1  | k1  | v11
1  | k2  | v12
2  | k1  | v21
2  | k2  | v22

Notation: k is for key, v is for value

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.

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):

data
id | c1  | c2  | k1  | k2
-------------------------
1  | 11  | 12  | v11 | v12
2  | 21  | 22  | v21 | v22

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.

The fix I’m thinking is to alias two columns:

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

Notation: a is for alias

The result of this would theoretically look like

data
id | c1  | c2  | a3  | a6 
------------------------- 
1  | 11  | 12  | v11 | v12
2  | 21  | 22  | v21 | v22

Note all a’s would technically be here, but 3 and 6 are the ones I’m interested in

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:06:53+00:00Added an answer on June 6, 2026 at 8:06 pm

    You can alias the entire table, for example dictionary as d1. Then refer to the column names in that table as d1.col1. For example:

    SELECT  d.id
    ,       d.c1
    ,       d.c2
    ,       d1.value as a3
    ,       d2.value as a6
    FROM    data as d
    LEFT JOIN
            dictionary as d1
    ON      data.id = d1.id
            and d1.key = 'k1'
    LEFT JOIN
            dictionary as d2
    ON      data.id = d2.id
            and d2.key = 'k2'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.