Professional Documents
Culture Documents
old-name as new-name
• select dept_name
• from department
• where building like ’%Watson%’;
String Operations
• For patterns to include the special pattern
characters (that is, % and \ ), SQL allows
the specification of an escape character.
• We define the escape character for a like
comparison using the escape keyword.
String Operations
• SQL allows us to search for
mismatches instead of matches by
using the not like comparison
operator.
• SQL:1999 also offers a similar to
operation, which provides more
powerful pattern matching than the
like operation.
Ordering the Display of Tuples
• List in alphabetic order all instructors in the Physics
department.
• select name
• from instructor
• where dept_name= ’Physics’
• order by name;
• select *
• from instructor
• order by salary desc , name asc;
• select course_id
• from section
• where semester = ’Fall’ and year = 2009;
The Union Operation
• Find the set of all courses taught either in Fall
2009 or in Spring 2010, or both.
The Union Operation
• Find the set of all courses taught either in Fall 2009 or in
Spring 2010, or both.
• (select course id
• from section
• where semester = ’Fall’ and year = 2009)
union
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
• (select course id
• from section
• where semester = ’Fall’ and year = 2009)
union all
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
The Intersect Operation
• Find the set of all courses taught in the Fall
2009 as well as in Spring 2010.
The Intersect Operation
• Find the set of all courses taught in the Fall 2009 as well as in
Spring 2010.
• (select course_id
• from section
• where semester = ’Fall’ and year = 2009)
intersect
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
• (select course_id
• from section
• where semester = ’Fall’ and year = 2009)
except
• (select course id
• from section
• where semester = ’Spring’ and year = 2010);
• select name
• from instructor
• where salary is null ;