0

I have a join SQL Request where the output of 2 tables is produced :

 ss= 'Select t.*, p.* from table1 t, table1 p where t.table2_id=p.table1_id'
 df = pd.read_sql_query(ss, self.db_con)

However, some columns have same name since the table is stripped. (ex: id, id ...)

How to get table.colname in the dataframe ?

Thanks

1
  • 1
    IMO it doesn't make much sense to join table with itself using the same id column... What are you trying to achieve? Commented Nov 17, 2016 at 21:01

1 Answer 1

1

You have to rename the conflicting columns with AS:

SELECT t.id AS t_id, p.id AS p_id, FROM table1 t, table2 p WHERE t.id = p.id
Sign up to request clarification or add additional context in comments.

2 Comments

Do I need to explicitely rename it ? (sometimes, I dont know the elements in advance , using *).
Basically yes. Similar question with better answer here: stackoverflow.com/questions/329931/sql-select-join-is-it-possible-to-prefix-all-columns-as-prefix

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.