I have an 1:m association.
symbols table has many rows in
company_key_statistics has column
createdAt which is timestamp indicating when row has been created.
I need to join latest
company_key_statistics, but I need only latest
For example I need to get
symbols and only their latest
So far I have tried this.
SELECT `symbols`.`id`, `symbols`.`symbol`, `statistics`. `marketCapitalization` FROM `symbols` LEFT JOIN (SELECT `s`.`companyId`, `s`.`marketCapitalization` FROM `company_key_statistics` AS `s` WHERE `s`.`companyId` = `symbols`.`id` ORDER by `createdAt` DESC LIMIT 1) AS `statistics` ON `symbols`.`id` = `statistics`.`companyId` WHERE `symbols`.`symbol` IN ('ORCL', 'SNAP');
But unfortunately I found that I can't use columns from parent query in
How can I achieve to this?