I have to create a query from two tables. Table 1 is the accounts table
and table 2 is the payments table. Each account can have many payments.
I have to create a query that lists all accounts with the last payment.
If there are no payments then the query displays no information for the
payments but lists the account information anyway. If there are
multiple payments then I need to pick up the last payment. Example:
id account_id cents
1 1 500
2 1 1000
if I run the following query:
select a.id, a.name, p.id, p.cents from accounts left outer join
payments p where accounts.id = payments.account_id; then I get
a.id a.name p.id p.name