Hamza ELKOUCH
Hamza ELKOUCH

Reputation: 3

Insert rows into a table with date conditions

I have two tables DGS and TFIFO and i want to insert all rows having: date.DGS > max(date.TFIFO).

I tried

INSERT INTO Tabla_Fifo ( Pieza, date )
SELECT [DGS].PIEZA, [DGS].DATE
FROM TFIFO, [DSG]
WHERE ((([DSG].DATE)>Max(TFIFO.DATE)));

but it doesn't works.

Thanks a lot :)

Upvotes: 0

Views: 39

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521299

You probably intended to use a subquery to find the max date:

INSERT INTO Tabla_Fifo (Pieza, date)
SELECT [DGS].PIEZA, [DGS].DATE
FROM [DSG]
WHERE [DSG].DATE > (SELECT MAX(DATE) FROM [TFIFO]);

I don't even see the point of joining to the TFIFO table, since you are only selecting values from DSG. Instead, I only involve the TFIFO table in the subquery.

Upvotes: 2

Related Questions