I am writing a small tool for managing the people registered to an association.
I have a table USERS
and a table CARDS
. Each user can have more than one card (because cards expire).
With one query I would like to extract ALL user information plus ALL card information only for the most recent card (field: ISSUEDATE).
Here is a very basic example:
USERS table
IDUSER NAME SURNAME
------------------------
1 Robert Hill
CARDS table
IDCARD IDOWNER ISSUEDATE DESC
----------------------------------------
1 1 2010-01-01 'CARD ONE'
2 1 2010-08-18 'CARD TWO'
Basically I would like to get back from my query these fields:
IDUSER NAME SURNAME IDCARD IDOWNER ISSUEDATE DESC
---------------------------------------------------------------
1 Robert Hill 2 1 2010-08-18 'CARD TWO'
I tried, but I cannot manage :(
EDIT: What happens if there is NO CARD linked to the user? (one user is registered but the association did not give him/her any card yet). Is there any way to adapt this query in order to get back user information anyway? The idea is to get all possible information for each user. This information is later used via JSON on ad ExtJS application.
Thanks for your answers.