What I am making is a block of code where it "balances" the load for support tickets on a website.

I know that my setup may (most likely will) not be the best. I'm looking for working, not a lecture on how to do everything and have it all setup.

I have the following:

ID (Auto)
partOf (The original ID number, used for threads)
rep (The service rep handling it)
-- Everything Else (like subject, from, message, etc) --

I would like my query to simply select everything (I need all fields) where the rep = whoever (it runs a loop of all reps, then figures out how many tickets they have open and from there I can handle it) and where partOf is distinct (or never seen again in that column).

After the query I count the number of rows found and determine the person with the lowest and assign the ticket to them.

I've done a little research, but most of what I read doesn't work, or I don't understand. (I really only know create, select, update, delete/drop/empty, and insert)

If you need a sample table, here you go:

| ID | partOf | rep |
| 01 |   01   |  1  |
| 02 |   01   |  1  |
| 03 |   02   |  2  |
| 04 |   03   |  3  |

mysql_num_rows for rep 1 would be 1, rep 2 would be 1, rep 3 would be 1 as well. (because partOf should only be counted in the query if it is unique)

Nevermind, found a fix.

Guess and check worked :P


SELECT DISTINCT partOf, rep FROM tickets