Combine 2 SQL queries into 1 table

I have 2 Requests:

Request 1:

SELECT w2.Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in ,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
 FROM w2
 INNER JOIN client
 ON w2.Don_Ordre = client.Client 
 WHERE client.Zone='CLR' 
 SORT BY w2.Avis ;

      

Request 2:

SELECT w3.Avis,w3.Cde_Sap,w3.Don_Ordre,w3.PN_in , w3.SN_in,w3.DATE2,w3.Statut_Cde,client.Zone
FROM w3
INNER JOIN client
ON w3.Don_Ordre = client.Client 
WHERE client.Zone='CLR' 
SORT BY w3.Avis;

      

I want to display these 2 queries in 1 page and SORT BY Avis. This does not work.

+3


source to share


1 answer


UNION ALL

, in the derived table. ORDER BY

on the result:

select * from
(
SELECT w2.Avis as Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in ,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
 FROM w2
 INNER JOIN client
 ON w2.Don_Ordre = client.Client 
 WHERE client.Zone='CLR' 

UNION ALL

SELECT w3.Avis,w3.Cde_Sap,w3.Don_Ordre,w3.PN_in , w3.SN_in,w3.DATE2,w3.Statut_Cde,client.Zone
FROM w3
INNER JOIN client
ON w3.Don_Ordre = client.Client 
WHERE client.Zone='CLR'
) dt
order by avis

      



As an alternative:

SELECT w2.Avis,w2.Cde_Sap,w2.Don_Ordre,w2.PN_in,w2.SN_in,w2.DATE2,w2.Statut_Cde,client.Zone
 FROM (select * from w2
       UNION ALL
       select * from w3) as w2
 INNER JOIN client
 ON w2.Don_Ordre = client.Client 
 WHERE client.Zone='CLR' 
 SORT BY w2.Avis ;

      

+1


source







All Articles