You can use Common Table Expression
WITH myUnion as
(SELECT
custom_qui.QuiID,
custom_sb_quoi.numqui,
custom_sb_quoi.CPAct1 AS CP,
custom_SB_quoi.Latitude_act AS Latitude,
custom_SB_quoi.Longitude_act AS Longitude
FROM custom_qui,
custom_sb_quoi
WHERE custom_qui.quiID = custom_sb_quoi.numqui
AND CPAct1 IS NOT NULL
UNION ALL
SELECT
custom_qui.QuiID,
custom_sb_quoi.numqui,
custom_qui.CP AS CP,
custom_qui.Latitude AS Latitude,
custom_qui.Longitude AS Longitude
FROM custom_qui,
custom_sb_quoi
WHERE custom_qui.quiID = custom_sb_quoi.numqui
AND CPAct1 IS NULL)
select * from myUnion WHERE ##WHERE## ORDER BY ##ORDERBY##
P.S. if the query above works well - you can simplify it- i.e.remove your conditions (CPAct1 IS NOT NULL
and CPAct1 IS NULL
- they combined give you the same result set as if you don't use them) and merge everything into 1 query
This should give the same result as the query with union above:
SELECT
custom_qui.QuiID,
custom_sb_quoi.numqui,
custom_sb_quoi.CPAct1 AS CP,
custom_SB_quoi.Latitude_act AS Latitude,
custom_SB_quoi.Longitude_act AS Longitude
FROM custom_qui INNER JOIN custom_sb_quoi on custom_qui.quiID = custom_sb_quoi.numqui
WHERE ##WHERE## ORDER BY ##ORDERBY##