Imagine the following two tables, named "Users" and "Orders" respectively:
ID NAME
1 Foo
2 Bar
3 Qux
ID USER ITEM SPEC TIMESTAMP
1 1 12 4 20150204102314
2 1 13 6 20151102160455
3 3 25 9 20160204213702
What I want to get as the output is:
USER ITEM SPEC TIMESTAMP
1 12 4 20150204102314
2 NULL NULL NULL
3 25 9 20160204213702
In other words: do a LEFT OUTER JOIN betweeen Users and Orders, and if you don't find any orders for that user, return null, but if you do find some, only return the first one (the earliest one based on timestamp).
If I use only a LEFT OUTER JOIN, it will return two rows for user 1, I don't want that. I thought of nesting the LEFT OUTER JOIN inside another select that would GROUP BY the other fields and fetch the MIN(TIMESTAMP) but that doesn't work either because I need to have "SPEC" in my group by, and since those two orders have different SPECs, they still both appear.
Any ideas on how to achieve the desired result is appreciated.