SQL in 10 minutes notes

Lesson 6 – Wildcard

SELECT prod_name 
FROM Products 
WHERE prod_name 
LIKE 'F%y';
% represents zero, one, or more characters at the specified location 
in the search pattern

SELECT prod_id, prod_name 
FROM Products 
WHERE prod_name 
LIKE '__ inch teddy bear';
The underscore is used just like %, but instead of matching multiple 
characters the underscore matches just a single character

SELECT cust_contact 
FROM Customers 
WHERE cust_contact 
LIKE '[JM]%' 
ORDER BY cust_contact;
The brackets ([]) wildcard is used to specify a set of characters, 
any one of which must match a character in the specified position

Lesson 7 – Creating Calculated Fields

SELECT CONCAT(vend_name, ' (', vend_country, ')') AS vender_infor 
FROM Vendors 
ORDER BY vend_name;

SELECT RTRIM(vend_name) + ' (' + RTRIM(vend_country) +')' AS vender_infor 
FROM Vendors
ORDER BY vend_name;

The RTRIM() function trims all space from the right of a value. By using RTRIM(), the individual columns are all trimmed properly.

An alias is just that, an alternatename for a field or value. Aliases are assigned with the AS keyword.

SELECT prod_id, quantity, item_price, quantity*item_price AS expanded_price
FROM OrderItems
WHERE order_num = 20008;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s