2010-05-14 7 views
1

J'ai deux mêmes tables. Je besoin de les syndicats de telle manière:Nom de la table SELECT qui se trouve à l'intérieur UNION

SELECT f1,f2, xxx 
FROM 
(SELECT  * 
FROM   tbl1 
UNION ALL 
SELECT  * 
FROM   tbl2) 

où xxx interrogerait pour un nom de table, où sont prises les champs et f2 f1. sortie Exemple:

123 345 'tbl1' -- this rows are from the first table 
121 345 'tbl1' 
121 345 'tbl1' 
123 345 'tbl1' 
124 345 'tbl1' 
125 345 'tbl2' -- this rows are from the second table 
127 345 'tbl2' 

Merci à l'avance.

Répondre

2
SELECT f1,f2, xxx 
FROM 
(SELECT  *, 'tbl1' as xxx 
FROM   tbl1 
UNION ALL 
SELECT  *, 'tbl2' as xxx 
FROM   tbl2) 
Questions connexes