Instruction
Nicely done! Here's a quick recap of what we learned today:
- Each query starts with
SELECT, followed by comma‐separated column names. To retrive all columns from a table, use the asterisk (*). - After
SELECTcomes theFROMcaluse which indicates the name of the table from which you want to retrive the above data. - Optionally, you can use a
WHEREclause to filter the rows. - You can use mathematical signs for comparison:
>,>=,=,<=,<,!=,<>. - You can check, whether a value is inside an interval using
BETWEEN. - You can compare string and text patterns using
LIKEand the following two wildcards:%for any number of characters (including zero)_for only one character
- To list more than one conditional expression, use the
ANDandORoperators as needed. Remember: grouping matters. If needed use parentheses to group expressions. NULLs are a little bit more complicated. You have to useIS NULLto check whether a value isNULL.- All conditions can be negated with the
NOToperator.
Now, let's put together all the information we've learned so far. Let's imagine a customer who walks in and wants to know if we have any cars that meet his needs.
Exercise
Select all columns for cars that:
- Were produced between 1999 and 2005.
- Are not Volkswagens.
- Have a model beginning with either
'P'or'F'. - Have a set price.
Stuck? Here's a hint!
Type:
SELECT * FROM Car WHERE ProductionYear BETWEEN 1999 AND 2005 AND Brand != N'Volkswagen' AND (Model LIKE N'P%' OR Model LIKE N'F%') AND Price IS NOT NULL;




