1“Stand firm in your refusal to remainconscious during algebra. In real life, Iassure you, there is no such thing asalgebra.”-- Fran Lebowitz,Social StudiesSQL: Structured Query LanguageINFO/COM S 230:Intermediate Web Design andProgrammingSQL“Real” database queriesHow do we really pose queries to arelational DBMS? Industry standard:using the language SQL.• Soon: How to use SQL via the MySQLDBMS.• After that: How to use SQL from PHPvia MySQL.• For now: How to write SQL queries.…via relational algebraTo do this, we’ll show how we canimplement each of the relational algebraoperators in SQL.SQL basics: selection andprojectionEasy PDF Creator is professional software to create PDF. If you wish to remove this line, buy it now.
has intentionally blurred sections.
Sign up to view the full version.
2SelectionσC(R) in SQL:SELECT *FROM RWHERE C;E.g.SELECT *FROM MOVIESWHERE Length > 150;201mins.2003The Return of theKing113mins.2002Chicago200420012000YearLengthTitle132mins.Million Dollar Baby135mins.A Beautiful Mind155mins.GladiatorConditionsWe can use the following conditions in the“WHERE” clause:= (equals – note not ==)< (less than)> (greater than)<= (less than or equal)>= (greater than or equal)<> (not equal)Conditions can be parenthesized and can use“AND”, “OR”, and “NOT”.SELECT *FROM MOVIESWHERE (Length > 150) AND (Title <>‘The Return of the King’);StringsCan have conditions on strings usingLIKE, with special characters%(matches 0 or more characters) and_(matches any single character).E.g.SELECT *FROM MoviesWHERE Title LIKE ‘%King%’Regular expressionsSome variants of SQL (such as MySQL) allow regular expressionmatchingSELECT *FROM MoviesWHERE Title REGEXP ‘[aeou]t’;201 mins.2003The Return of theKing113 mins.2002Chicago200420012000