sql - Left join without multiple rows from right table -


i have 2 tables (user , salary). want left join user salary. each user want name , salary. in case have no salary field can left empty. far left join need. want 1 row per user. due defects there can several salaries 1 user (see table salary). want 1 row per user can selected randomly (or top 1). how do that? expected output presented in bottom.

user table:

user name 1    adam 2    al 3    fred 

salary table

user  salary 1     1000 2     2000 2     2000 

expected table:

user name  salary 1    adam  1000 2    al    2000  3    fred  null 

changed user userid user reserved word in sql

select u.userid, u.name, max(s.salary) usertable u left join salarytable s on u.userid = s.userid group u.userid, u.name 

sql fiddle: http://sqlfiddle.com/#!6/ce4a8/1/0


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -