Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Sunday, March 3, 2013

UPDATE .. FROM syntax difference in Sql Server and Oracle


There is syntactical difference in few operations in SQL in Oracel and Sql server

For example: UPDATE .. FROM

UPDATE students
     SET grade='A'
FROM students s 
INNER JOIN students_marks sm ON sm.student_id = s.student_id
WHERE sm.total_marks>80;

The above query syntax works in Sql Server but will fail in Oracle.

Below is the Oracle alternative.

UPDATE 
     (SELECT grade 
             FROM students s
             INNER JOIN students_marks sm ON sm.student_id = s.student_id
             WHERE sm.total_marks>80) t 
SET t.grade='A';


Below is the block diagram for the Oracle query