sql - How to select the latest rows where each contains one value of all possible values found in a domain table? -


id username city        registeryear 1  user1    new york    1990 2  user2    san diego   2008 3  user3    chicago     2009 4  user4    los angeles 1994 5  user5    san diego   2004  

domain table

id  city 1   new york 2   san diego 3   los angeles 4   chicago 

in example query return:

user1 user2 user3 user4 

well, first need replace "city" in first table id column of domain table. "city" not primary key.

after that:

select u.username   users u,        domain d  d.id = u.cityid        , u.registeryear = (select max(u2.registeryear)                                users u2                               u2.cityid = u.cityid); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -