I have two tables, like so:
a.id, a.created, a.b
b.id, b.name, b.created
I want all the records from the table b to be sorted by the a.created timestamp.
I've been trying something of the following:
SELECT b.id, b.name FROM b JOIN a ON a.b = b.id ORDER BY b.created DESC
But it always returns multiple records from b when really all I want is one match of a for every row of b.
I tried to use a SELECT subquery:
SELECT b.id, b.name, (SELECT a.created AS a_c FROM a WHERE
a.b = b.id) AS a_c FROM b ORDER BY a_c DESC
But I also want to be able to pull a.id as well.
Is there a JOIN statement I could use or should I use two subqueries? This is going to be a pretty important function in my application so I want the performance to be above par!