Update in the same table

Asked

Viewed 422 times

-2

I have this table like this:

CODIGO_AULA DATA_AULA  TURMA
----------- ---------- ----------
1           2018-01-19 MEC-001
2           2018-01-19 MEC-001
1           2018-01-20 MEC-001
2           2018-01-20 MEC-001
1           2018-01-21 MEC-001
2           2018-01-21 MEC-001
1           2018-01-22 MEC-001
2           2018-01-22 MEC-001

I need to make an update in the same according to this past situation,I passed by parameter the date : 2018-01-20

Thus remaining:

1           2018-01-21 MEC-001
2           2018-01-21 MEC-001
1           2018-01-22 MEC-001
2           2018-01-22 MEC-001
1           2018-01-23 MEC-001
2           2018-01-23 MEC-001

All he’s gonna do is move the date I went through to the bottom of the chart. What I need and take is to make an update of the date I passed and came up ?

  • 1

    Your doubt was not very clear. Could you explain us better?

  • 1

    Clarify your specific issue or add other details to highlight exactly what you need.

3 answers

0

Good afternoon,

This very vague your need, if you want to update between a date range use BETWEEN

update suaTabela set seuCampo = seuDado where seuCampo between dataInicial and dataFinal;

0

From what I understand, there’s a clasp missing WHERE in his UPDATE for you to make the desired change, as a suggestion, use a predicate with the date:

UPDATE TBL_AULA SET CAMPO_A_ALTERAR = VALOR_ALTERADO WHERE DATA > '2018-01-20';

0

About UPDATE, the other answers are ok and I agree that you are a little confused to understand. But just to clarify more:

UPDATE TBL_AULA SET DATA_AULA = '2018-01-23' WHERE DATA = '2018-01-20'; 

With this, all the records of the 20th will be of the 23rd.

Taking into consideration this question: "it will only move from the date I passed to the end of the table. What I need and take is to make an update of the date I passed and came up?"

Once you have made this UPDATE, the order of the records in your table will not change. It will be like this:

CODIGO_AULA DATA_AULA  TURMA
----------- ---------- ----------
1           2018-01-19 MEC-001
2           2018-01-19 MEC-001
1           2018-01-23 MEC-001
2           2018-01-23 MEC-001
1           2018-01-21 MEC-001
2           2018-01-21 MEC-001
1           2018-01-22 MEC-001
2           2018-01-22 MEC-001

If you want it to be displayed in order, you will have to make an ordered selection (SELECT with ORDER BY) taking into account the DATA_AULA field.

Browser other questions tagged

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