I'm trying to select a column from another table like I used to do in MSSQL:
select * , Date = (select top 1 Date from [dbo].TableB where status = 1 order by Date desc)
from [dbo].TableA
How can I do that in PostgreSQL?
Additional sample data:
TableA
Names
Richards
Marcos
Luke
Matthew
John
TableB
Date Status
2016-01-01 1
2016-01-02 0
2016-01-03 1
2016-01-04 1
2016-01-05 1
Expected Output:
Name Date
Richards 2016-01-02
Marcos 2016-01-02
Luke 2016-01-02
Matthew 2016-01-02
John 2016-01-02
Thanks!
select * , (select NewColumn from [dbo].TableB) as NewColumnnot work?tableb? If not, it will return multiple results and cause an error most likely...