If you want an answer with a particular string in each row,use that constant as an expression. Likes (drinker,beer) SELECT drinker, likes Bud'AS whoLikesBud FROM Likes W HERE beer 'Bud'; drinker whoLikesBud Sally likes Bud Fred likes Bud
• If you want an answer with a particular string in each row, use that constant as an expression. Likes(drinker, beer) SELECT drinker, 'likes Bud'AS whoLikesBud FROM Likes W HERE beer ='Bud'; drinker whoLikesBud Sally likes Bud Fred likes Bud … …
Example Find the price Joe's Bar charges for Bud. Sellsbar,beer,price) SELECT price FROM Sells WHERE bar=Joe''s Bar'AND beer =Bud'; Note:two single-quotes in a character string represent one single quote. Conditions in WHERE clause can use logical operators AND,OR,NOT and parentheses in the usual way. Remember:SQL is case insensitive.Keywords like SELECT or AND can be written upper/lower case as you like. Only inside quoted strings does case matter
Example z Find the price Joe's Bar charges for Bud. Sells(bar, beer, price) SELECT price FROM Sells W H ERE bar= 'Joe''s Bar' AND beer = 'Bud'; z Note: two single-quotes in a character string represent one single quote. z Conditions in W HERE clause can use logical operators AND, OR, NOT and parentheses in the usual way. z Remember: SQL is case insensitive. Keywords like SELECT or AND can be written upper/lower case as you like. – Only inside quoted strings does case matter
Patterns WHERE clauses can have conditions in which a string is compared with a pattern,to see if it matches General form: <Attribute>LIKE <pattern>or <Attribute>NOT LIKE <pattern Pattern is a quoted string with %="any string";_="any character
Patterns • WHERE clauses can have conditions in which a string is compared with a pattern, to see if it matches. General form: <Attribute> LIKE <pattern> or <Attribute> NOT LIKE <pattern> Pattern is a quoted string with % = “any string”; _ = “any character
Pattern Example Find drinkers whose phone has exchange 555. Drinkers(name,addr,phone) SELECT name FROM Drinkers WHERE phone LIKE'%555-__';
Pattern Example z Find drinkers whose phone has exchange 555. Drinkers(name, addr, phone) SELECT name FROM Drinkers WHERE phone LIKE '%555-_ _ _ _’;
Nulls Tuples in SQL relations can have NULL as a value for one or more components. Meaning depends on context.Two common cases: Missing value e.g.,we know Joe's Bar has some address,but we don't know what it is. Inapplicable e.g.,the value of attribute spouse for an unmarried person
Nulls • Tuples in SQL relations can have NULL as a value for one or more components. • Meaning depends on context. Two common cases: • Missing value : e.g., we know Joe’s Bar has some address, but we don’t know what it is. • Inapplicable : e.g., the value of attribute spouse for an unmarried person