Select multiple rows to columns in SQL server -


i want below output through sql server.

table a

| id   |   name   | 2016 | 2017 |    - - - - - - - - -  - - - - - - -  | 1    |  abcdefg |      |      | | 2    |  xyzlmon |      |      | 

table b

| id   | value | year |    - - - - - - - - - - - | 1    |  f    | 2016 | | 1    |  g    | 2017 | 

output

| id   |   name   | 2016 | 2017 |    - - - - - - - - -  - - - - - - -  | 1    |  abcdefg |  f   |  g   | | 2    |  xyzlmon |      |      | 

try this:

select      tbla.id id,      tbla.name name,      (select          value       tblb       tblb.id = tbla.id       , tblb.year ='2016') 2016,       (select            value        tblb        tblb.id = tbla.id        , tblb.year ='2017') 2017  tbla; 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -