How can I do Join two tables and do Pivot dynamically

  • A+
Category:Languages

I have two tables, A and B

A ( id, name )
B ( a_id, key, value )

table with some values

**A table**  -----------------------------    id        |      name -----------------------------     1        |      sorabh     2        |      john -----------------------------  **B table**  -------------------------------------------------      a_id    |     key     |     value -------------------------------------------------       1      |    looks    |    handsome       1      |    lazy     |    yes       1      |    car      |    honda       2      |    phone    |    948373221       1      |    email    |    some@ccid.com ------------------------------------------------- 

Now what i am trying to achieve is a follow, with single query, inner join, cross join, etc.

SELECT * FROM A CROSS JOIN B WHERE A.id=1 

and result must be something like

--------------------------------------------------------------------   id   |   name   |    looks   |   lazy  |    car   |   email --------------------------------------------------------------------    1   |  sorabh  |   handsome |   yes   |  honda   | some@ccid.com  -------------------------------------------------------------------- 

 


There are two type of SQL statements.

  1. Static SQL is SQL statements in an application that do not change at runtime and, therefore, can be hard-coded into the application.
  2. Dynamic SQL is SQL statements that are constructed at runtime; for example, the application may allow users to enter their own queries.

You can use Dynamic SQL for generate query.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: