>Salve credo di avere un vuoto ma un serio vuoto di memoria e
>non riesco a finire una select con inner join doppia da una tabella
>anagrafica verso una seconda tabella comuni , in poche parole
>dovrei prelevare per ben due volte dalla tabella comuni due valori diversi
dovrai fare due join sulla stessa tabella sfruttando SQL e i suoi Alias:
USE tempdb;
GO
CREATE TABLE #Anagrafica
(
IdUtente int IDENTITY(1, 1) NOT NULL PRIMARY KEY
, Nome varchar(30) NOT NULL
, IdComuneNascita smallint NOT NULL
, IdComuneResidenza smallint NOT NULL
);
GO
CREATE TABLE #Comuni
(
IdComune smallint NOT NULL PRIMARY KEY
, Comune varchar(50) NOT NULL
);
GO
INSERT INTO #Comuni (IdComune, Comune)
VALUES
(1, 'Firenze'),
(2, 'Roma');
GO
INSERT INTO #Anagrafica (Nome, IdComuneNascita, IdComuneResidenza)
VALUES
('Alessandro', 1, 2),
('Michael', 2, 1),
('Alex', 2, 2);
GO
SELECT
A.IdUtente
, A.Nome
, ComuneResidenza = RES.Comune
, ComuneNascita = NAS.Comune
FROM
#Anagrafica A
JOIN #Comuni RES ON A.IdComuneResidenza = RES.IdComune
JOIN #Comuni NAS ON A.IdComuneNascita = NAS.IdComune;
GO
DROP TABLE #Anagrafica;
GO
DROP TABLE #Comuni;
GO
Alessandro Alpi | SQL Server MVP
MCP|MCITP|MCTS|MCT
http://blogs.dotnethell.it/suxstellino
http://suxstellino.wordpress.com
http://mvp.microsoft.com/profiles/Alessandro.Alpi