Union Junction Operator

Asked

Viewed 41 times

-1

I need to present the departments that had stock movement in Feb/2018 and those that had in Mar/2018. I need to use a union operator to show the results of the two queries each of them returning the one-month departments. In each query I should avoid repeated departments. I need to show the code and name of the department by ordering by the code of the same. This table below is the stock movement table (MOVESTOQUE)inserir a descrição da imagem aqui

My department table (DEPARTMENT) is this: CODDEP 1, 2, 3, 4, 5, 6, 7, 8, 9 DESCRIPTION Sales (1), Purchases(2), IT(3), Management(4), Warehouse(5), Directorate(6), Financial(7), Stock(8), Customer Service(9))

CODDEP is a column and DESCRICAO is another column.

  • I couldn’t understand the question. First, what is the database? Mysql, Postgree, Oracle? " I need to use a union operator to show the results of the two queries each returning the departments for a month." What do you mean? If the results are all in the same table it is not necessary to perform any union, it is only code refinement.

  • Hello. DB is Postgress. The original question I have to solve is this: " Present the departments that had stock movement in Feb/2018 and those that had in Mar/2018. Use a union operator to display the results of the two queries each returning the one-month departments. In each query, repeated departments should be avoided. Show code and department name ordering by the code of the same."

1 answer

0


select distinct
coddep,
dthora

from
movestoque

where
dthora between '2018-02-01' and '2018-02-28'

UNION

select distinct
coddep,
dthora

from
movestoque

where
dthora between '2018-03-01' and '2018-03-31'
  • Shoow!! With this example I can solve the next two questions. Brigadão and Rodrigo!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.