All pastes #526207 Raw Edit

Stuff

public text v1 · immutable
#526207 ·published 2007-05-31 18:30 UTC
rendered paste body
I`ve stack on such problem (definition above):
i have 2 tables:

Table data:
	id (int, for this table the field is unique (primary key))
	points (int, how much points the owner of this id earned)

Table users:
	id (foreign key from table data, in this table it is possible to meet some id more than once)
	name (varchar, the field is unique (just some names assigned to an id`s))
	uses (int, this field indicates how much times some id have used some name)

What all this stuff stays for:
	So, data table stores the accounts data - unique ID for each user and hes earned points, BUT -
	Nicknames are not statically assigned for users - they can change and accordingly how many
	times user changes to nickname "asd" so much times increments field 'uses' in table users (starting from 1 of course).

What i want:
	I need to make a top of users having the best results, this means ->
		* get a top of users having more points from table data, remember those id`s
		* match those id`s in 'users' table and for each id select only one nickname which was most often used by this user

Any ideas? Beforehand is grateful for any advance.