Very good. I have a table called ALBARAN_SALES in which I must do a replica of a tuple as the following exercise asks:
REPLICATE_ALBARAN. Generate the replication of a sales slip (including lines). The delivery note to be replicated will be the first found by ordering by company, commercial organization, serial_number, invoice number and exercise in descending order. East new delivery note will have the same data as the replicated delivery note, except the delivery note number This number will be the maximum + 1 that exists in the table of delivery notes (ALBARAN_SALES_FORMATION) for the serial number of the delivery note that we are replicating.
Company, commercial_organization, serial_number, number_albaran and exercise are fields of said table and together they form the PK.
So far I have developed:
TO FIND THE REGISTRATION:
SELECT *
FROM ALBARAN_VENTAS_FORMACION
WHERE NUMERO_ALBARAN IN(
SELECT *
FROM (
SELECT NUMERO_ALBARAN, EMPRESA, ORGANIZACION_COMERCIAL, NUMERO_SERIE, NUMERO_ALBARAN, EJERCICIO
FROM ALBARAN_VENTAS_FORMACION
ORDER BY EMPRESA DESC, ORGANIZACION_COMERCIAL DESC, NUMERO_SERIE DESC, NUMERO_ALBARAN DESC, EJERCICIO DESC)
WHERE ROWNUM =1)
TO FIND THE RECORD WITH THE HIGHEST NUMBER TO WHICH TO ADD +1
SELECT NUMERO_ALBARAN
FROM (
SELECT NUMERO_ALBARAN
FROM ALBARAN_VENTAS_FORMACION
ORDER BY NUMERO_ALBARAN DESC)
WHERE ROWNUM = 1;
I do not know how to put them together to do an INSERT, since I have tried it and it gives me an error, even though the querys work perfectly separately. Could you give me a hand? Thank you very much:)