If I have a User table, like this:
UserId Name
------ ----
1 Jim
2 Mark
and an Order table like this:
OrderId UserId
------- ------
1 1
2 1
3 1
4 2
How can I just take any single Order of Jim’s? It doesn’t matter which, I just want one.
I have this:
Joining isn’t the issue, it’s just limiting it to one result as there are obviously 3.
SELECT * FROM User u
LEFT OUTER JOIN Order o on u.UserId = o.UserId
Thanks in advance.
This will select the first matched row:
If you know which user you’re looking for ahead of time, you can add that to the WHERE clause:
And, if you ever need to make sure you’re getting the First, or Most Recent order, you can use :