Monday 5 June 2017

How to populate query with result from different table?

I have two tables. Table A and table B. Table A has a column that is a reference to the primary key to table B. I want to run a select query on table A and then populate the column that referrers to B with all of the data in that row of B.

SELECT * from A a LEFT JOIN B b ON a."b_id" = b."id"  WHERE ...

That gives a result with each row containing all of the columns of A and all of the columns of B. It is a confusing mess to figure out which column is from which table. I want to be able to do something like.

row.A."column name"
row.B."column name"

I don't want to have to rename every single column using AS. There must be a better way to do this.



via user3552325

No comments:

Post a Comment