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 10, 2018 in Python by ariaholic
• 7,320 points
14 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,120 points

Related Questions In Python

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 in Python by SDeb
• 9,540 points
83 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 in Python by Nymeria
• 3,500 points
32 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 in Python by Firoz
38 views
+2 votes
2 answers

How can I replace values with 'none' in a dataframe using pandas

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

answered Aug 13, 2018 in Python by bug_seeker
• 14,970 points
2,434 views
0 votes
1 answer

How to perform web scraping with python?

Hey, there are various libraries used in ...READ MORE

answered Apr 20, 2018 in Python by aayushi
• 750 points
164 views
0 votes
1 answer

how to find factorial of a number?

You can find factorial by many ways. ...READ MORE

answered May 4, 2018 in Python by aayushi
• 750 points
19 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2 in Python by anonymous
100 views
0 votes
1 answer

How to print first character of each word in upper case of a string in Python

You can use split() using space as ...READ MORE

answered Jun 1, 2018 in Python by george
• 200 points
1,021 views
0 votes
1 answer

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

Try looking the given link for better ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 56,120 points
14 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
• 56,120 points
281 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.