SELECT
 kWypDane.idFilmu,
 kWypDane.dataW1 AS dataW,
 kWypDane.dataZ1 AS dataZ
INTO tWypozyczenia
FROM (
	SELECT tFilmy.idFilmu, FW.dataW1 as dataW, FW.dataZ1 as dataZ
	FROM FW INNER JOIN tFilmy ON (FW.rok = tFilmy.rok) AND (FW.tytul = tFilmy.tytul)
	WHERE (((FW.dataW1) Is Not Null))

	union all

	SELECT tFilmy.idFilmu, FW.dataW2, FW.dataZ2
	FROM FW INNER JOIN tFilmy ON (FW.rok = tFilmy.rok) AND (FW.tytul = tFilmy.tytul)
	WHERE (((FW.dataW2) Is Not Null))

	union all

	SELECT tFilmy.idFilmu, FW.dataW3, FW.dataZ3
	FROM FW INNER JOIN tFilmy ON (FW.rok = tFilmy.rok) AND (FW.tytul = tFilmy.tytul)
	WHERE (((FW.dataW3) Is Not Null))

	union all

	SELECT tFilmy.idFilmu, FW.dataW4, FW.dataZ4
	FROM FW INNER JOIN tFilmy ON (FW.rok = tFilmy.rok) AND (FW.tytul = tFilmy.tytul)
	WHERE (((FW.dataW4) Is Not Null))

	UNION ALL SELECT tFilmy.idFilmu, FW.dataW5, FW.dataZ5
	FROM FW INNER JOIN tFilmy ON (FW.rok = tFilmy.rok) AND (FW.tytul = tFilmy.tytul)
	WHERE (((FW.dataW5) Is Not Null))
) as kWypDane;
