Interview Question
Country: United States
Why Add new column
UPDATE p1 SET p1.LastName='Test' FROM Persons P1
JOIN Persons p2 ON p1.P_Id = p2.P_Id
WHERE p1.p_id IN (SELECT TOP 2 p_id from Persons ORDER By p_id desc);
why do u join this table ? would nt this gives the same result ??
UPDATE p1 SET p1.LastName='Test' FROM Persons P1
where p1.p_id IN (SELECT TOP 2 p_id from Persons ORDER By p_id desc);
Are we allowed to modify the table? If yes, then the best strategy is to add an extra column column called "last_update_date". Now, you can easily query for extracting incremental records from the table.
- chandershivdasani August 22, 2012