eut.kop (11/26/2015)
I wish to have something similar (also the layout should reflect the hierarchical tree)horror
| titolo 1
| titolo 2
fantascienza
| titolo 3
| | titolo n (this is a second level)
but now you make me understand my relationship between tables don't permit this.
Thanks
Mara
Yes, you can currently have only 2 levels.
CREATE table categoria(
[id_categoria] [int] NOT NULL,
[categoria] [nvarchar](50) NULL
);
INSERT INTO categoria
VALUES
(1, 'horror'),
(2, 'fantascienza');
CREATE table film(
[id_film] [int] NOT NULL,
[film] [nvarchar](50) NULL,
[fk_categoria] [int] NULL
);
INSERT INTO film
VALUES
(1,'titolo', 1),
(2,'titolo', 1),
(3,'titolo', 2);
select title from
(
select [fk_categoria], [id_film], title= replicate(' ',3)+[film]
from film
union all
select
[id_categoria], null, title = [categoria]
from categoria
) as t
order by [fk_categoria], [id_film]