Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
for xml path
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
create table table1 ( Id INT PRIMARY KEY, Descripcion NVARCHAR(20), Tipo INT ); create table table2 ( Id INT PRIMARY KEY, Nombre NVARCHAR(80), IdTabla1 INT, constraint table2_table1_fk foreign key (IdTabla1) references table1(Id) ); create table table3 ( Id INT PRIMARY KEY, Nombre NVARCHAR(80), IdTabla1 INT, constraint table3_table1_fk foreign key (IdTabla1) references table1(Id) ); insert into table1 (id, descripcion, tipo) values (1, 'Descripcion prueba 1', 0), (2, 'Descripcion prueba 2', 2); insert into table2 (id, nombre, IdTabla1) values (1, 'ABC', 1), (2, 'DEF', 1), (3, 'HIJ', 2); insert into table3 (id, nombre, IdTabla1) values (1, '123', 1), (2, '456', 2), (3, '789', 2); select t1.id, t1.descripcion, t1.tipo, stuff((select ',' + t2.nombre from table2 t2 where t2.IdTabla1 = t1.id order by t2.id for xml path('')),1,1,'') as ValoresTabla2, stuff((select ',' + t3.nombre from table3 t3 where t3.IdTabla1 = t1.id order by t3.id for xml path('')),1,1,'') as ValoresTabla3 from table1 t1 order by t1.id;
View schema
Execution time: 0,02 sec, rows selected: 2, rows affected: 8, absolute service time: 0,2 sec
fork mode
|
history
id
descripcion
tipo
ValoresTabla2
ValoresTabla3
1
1
Descripcion prueba 1
0
ABC,DEF
123
2
2
Descripcion prueba 2
2
HIJ
456,789