I
I
Illarion Labahua2017-09-04 10:58:05
Oracle
Illarion Labahua, 2017-09-04 10:58:05

How to merge multiple selections without using union?

I have a set of samples that differ only in the value of one parameter, which takes a set of values ​​(0001, 0002, 0003 - 0099)
How can I combine a group of queries without using UNION?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2017-09-04
@Dronablo

WITH 
--один запрос
SINGLE_QUERY AS
  ( SELECT '0001' AS GROUP_ID, 'Moscow' AS V1, 1300 AS V2 FROM DUAL
  UNION ALL
  SELECT '0001' AS GROUP_ID, 'London' AS V1, 900 AS V2 FROM DUAL
  UNION ALL
  SELECT '0001' AS GROUP_ID, 'New York' AS V1, 1600 AS V2 FROM DUAL
  UNION ALL
  SELECT '0001' AS GROUP_ID, 'Berlin' AS V1, 1000 AS V2 FROM DUAL
  ),
  --список групп
  GROUPS AS
  ( SELECT TO_CHAR(LEVEL,'0009') GROUP_ID FROM DUAL CONNECT BY LEVEL<=99
  )
--для проверки
--select group_id, v1, v2 from single_query;
--select group_id from groups;
--результат
SELECT GROUPS.GROUP_ID,
  SINGLE_QUERY.V1,
  SINGLE_QUERY.V2
FROM SINGLE_QUERY,
  GROUPS
ORDER BY 1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question