I have a martial arts website where I have users in one table and the belts they have earned in another. Here are some example tables / data to help describe my problem:
Users
table :
+---------------------+
| Users |
+---------------------+
| userid | name |
+---------------------+
| 1 | Fred Smith |
+---------------------+
Belts
table :
+------------------------------------------+
| id | userid | belt_colour | awarded_date |
+------------------------------------------+
| 1 | 1 | blue | 2007-01-01 |
+------------------------------------------+
| 2 | 1 | purple | 2008-01-01 |
+------------------------------------------+
| 2 | 1 | brown | 2009-01-01 |
+------------------------------------------+
My problem is this: When you click brown, to view all brown belts I want you to see Fred. I DO NOT want Fred to appear in lists of blue and purple belts (which is what is happening at the moment).
I am struggling to come up with a query that goes something like this:
show me all users where belt=$belt but only if they do not have an entry for a higher belt.
Another example: I am purple but I show up in blue list because details of my blue belt are in the belts table too :-(
Any assistance greatly appreciated!