finding an empty association
| From: | Terry Romine | Date: | Sat, 29 Jun 2002 04:02:35 +0000 |
| Subject: | finding an empty association | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-20196@lists.php.net to get a copy of this message | ||
I have an interesting project where I need to find an agent_id from one table such that he has the least number of associated records (or preferably none) in a second table. Simple definition of the tables is:
Agents Table:
AgentID int primary key auto_increment
FName, LName and other details of this agent
Users Table:
UserID int primary key auto_increment
AgentID int --> AgentsTable
Orders, Datestamp, other details
The Agent is assigned to the User on a rotation basis, where an Agent who does not have any assignments, or has the least number is the next one to be picked.
Is it possible to do a join of some kind (I'm not too good at joins) that would determine the Agent with the least number of associated records in the User table?
Terry