How to replace id with attribute corresponding to id of another table

+1 vote

Using SQLAlchemy, I can query a bunch of files for their names and who created them:

>>> DBSession.query(Version.name, Version.created_by_id).filter(Version.id.in_(versions_list)).all()
[('file1', 1), ('file2', 2), ('file3', 3)]

The Version.created_by_id corresponds to the user ID. All users reside in a separate table:

>>> DBSession.query(User.id, User.name).all()
[(1, 'Abe'), (2, 'Cal'), (3, 'Dan')]

How can I, with one query, get this result back when I query my files?

[('file1', 'Abe'), ('file2', 'Cal'), ('file3', 'Dan')]
May 11, 2018 in Python by aryya
• 7,460 points
2,502 views

1 answer to this question.

0 votes

Use the following query statement and let me know as wether it worked

SELECT 
   name, color, shape
FROM 
   table1
      INNER JOIN 
         table2 ON table1.color_id = table2.color_id
      INNER JOIN 
         table3 ON table1.shape_id = table3.shape_id
answered Aug 8, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
0 answers

How to replace id with attribute corresponding to id of another table?

Using SQLAlchemy, I can query a bunch ...READ MORE

Oct 3, 2018 in Python by eatcodesleeprepeat
• 4,710 points
712 views
0 votes
1 answer

How to get rid of tensorflow verbose messages with Keras?

If you are using TensorFlow 0.12, you ...READ MORE

answered Jan 24, 2019 in Python by SDeb
• 13,300 points
4,691 views
0 votes
1 answer

How to zip with a list output in Python instead of a tuple output?

Good question - Considering that you are ...READ MORE

answered Feb 7, 2019 in Python by Nymeria
• 3,560 points
1,797 views
0 votes
1 answer

How to get domain name of email ID?

You can use the split method to split the ...READ MORE

answered Mar 28, 2019 in Python by Firoz
1,281 views
0 votes
1 answer

Replace values in data frame with valued of another dataframe.

Hi @Puneeth, you use something like this: f ...READ MORE

answered May 30, 2019 in Python by Ashish
4,088 views
0 votes
1 answer

How to get the multiplication table of any number using list comprehension?

Hey @Neha, you can use something like ...READ MORE

answered Jul 8, 2019 in Python by Sakshi
6,715 views
0 votes
0 answers
+2 votes
1 answer

How to check the state of a user given instance id using filters

Seems like the "ec2_con_re.instances" you are using ...READ MORE

answered Aug 1, 2019 in Python by Aishwarya
923 views
0 votes
1 answer

How to replace values with None in Pandas data frame in Python?

Actually in later versions of pandas this ...READ MORE

answered Aug 30, 2018 in Python by Priyaj
• 58,020 points
11,770 views
0 votes
1 answer

How to sort a list of strings?

Try  items = ["live", "like", "code", "cool", "bug"] ...READ MORE

answered Jul 27, 2018 in Python by Priyaj
• 58,020 points
870 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP