diff --git a/Is Null/Exercise_IS NULL.sql b/Is Null/Exercise_IS NULL.sql new file mode 100644 index 0000000..2b7c522 --- /dev/null +++ b/Is Null/Exercise_IS NULL.sql @@ -0,0 +1,5 @@ +/* Exercise: Get the orders that are not shipped */ + +SELECT * +FROM orders +WHERE shipped_date IS NULL \ No newline at end of file diff --git a/Is Null/mySQL_IS NULL.sql b/Is Null/mySQL_IS NULL.sql new file mode 100644 index 0000000..f2d432a --- /dev/null +++ b/Is Null/mySQL_IS NULL.sql @@ -0,0 +1,8 @@ +USE sql_store; + +SELECT * +FROM customers +WHERE phone IS NULL /* You can also do IS NOT NULL and it will show up with people who have phone numbers */ + + + diff --git a/More Operators/EXERCISE_BETWEEN_STATEMENT.sql b/More Operators/EXERCISE_BETWEEN_STATEMENT.sql new file mode 100644 index 0000000..3a4f545 --- /dev/null +++ b/More Operators/EXERCISE_BETWEEN_STATEMENT.sql @@ -0,0 +1,5 @@ +SELECT * +FROM customers +WHERE birth_date BETWEEN '1990-01-01' AND '2000-01-01' + + diff --git a/More Operators/EXERCISE_IN_STATEMENT.sql b/More Operators/EXERCISE_IN_STATEMENT.sql new file mode 100644 index 0000000..652e3ea --- /dev/null +++ b/More Operators/EXERCISE_IN_STATEMENT.sql @@ -0,0 +1,7 @@ +/* Exercise: +Return products with + quantity in stock equal to 49,38,72 */ + +SELECT * +FROM products +WHERE quantity_in_stock IN (49,38,72) \ No newline at end of file diff --git a/More Operators/EXERCISE_LIMIT.sql b/More Operators/EXERCISE_LIMIT.sql new file mode 100644 index 0000000..3c973c3 --- /dev/null +++ b/More Operators/EXERCISE_LIMIT.sql @@ -0,0 +1,4 @@ +SELECT * +FROM customers +ORDER BY points DESC +LIMIT 3 -- This should always happen last!! diff --git a/More Operators/EXERCISE_OPERATORS copy.sql b/More Operators/EXERCISE_OPERATORS copy.sql new file mode 100644 index 0000000..25ab75b --- /dev/null +++ b/More Operators/EXERCISE_OPERATORS copy.sql @@ -0,0 +1,5 @@ +SELECT * +FROM customers +WHERE address LIKE '%tr%' OR address LIKE '%Av%' OR phone LIKE '%9' + + diff --git a/More Operators/EXERCISE_OPERATORS.sql b/More Operators/EXERCISE_OPERATORS.sql new file mode 100644 index 0000000..25ab75b --- /dev/null +++ b/More Operators/EXERCISE_OPERATORS.sql @@ -0,0 +1,5 @@ +SELECT * +FROM customers +WHERE address LIKE '%tr%' OR address LIKE '%Av%' OR phone LIKE '%9' + + diff --git a/More Operators/EXERCISE_ORDERBY.sql b/More Operators/EXERCISE_ORDERBY.sql new file mode 100644 index 0000000..19e72e8 --- /dev/null +++ b/More Operators/EXERCISE_ORDERBY.sql @@ -0,0 +1,4 @@ +SELECT *, quantity * unit_price AS total_price +FROM order_items +WHERE order_id = 2 +ORDER BY total_price DESC diff --git a/More Operators/Is Null/Exercise_IS NULL.sql b/More Operators/Is Null/Exercise_IS NULL.sql new file mode 100644 index 0000000..2b7c522 --- /dev/null +++ b/More Operators/Is Null/Exercise_IS NULL.sql @@ -0,0 +1,5 @@ +/* Exercise: Get the orders that are not shipped */ + +SELECT * +FROM orders +WHERE shipped_date IS NULL \ No newline at end of file diff --git a/More Operators/Is Null/mySQL_IS NULL.sql b/More Operators/Is Null/mySQL_IS NULL.sql new file mode 100644 index 0000000..f2d432a --- /dev/null +++ b/More Operators/Is Null/mySQL_IS NULL.sql @@ -0,0 +1,8 @@ +USE sql_store; + +SELECT * +FROM customers +WHERE phone IS NULL /* You can also do IS NOT NULL and it will show up with people who have phone numbers */ + + + diff --git a/More Operators/Regular Expressions/EXERCISE_REGEXP1.sql b/More Operators/Regular Expressions/EXERCISE_REGEXP1.sql new file mode 100644 index 0000000..57ad934 --- /dev/null +++ b/More Operators/Regular Expressions/EXERCISE_REGEXP1.sql @@ -0,0 +1,5 @@ +/* REGEXP EXERCISE 1 */ + +SELECT * +FROM customers +WHERE first_name REGEXP 'elka|ambur' \ No newline at end of file diff --git a/More Operators/Regular Expressions/EXERCISE_REGEXP2.sql b/More Operators/Regular Expressions/EXERCISE_REGEXP2.sql new file mode 100644 index 0000000..e3ea6b8 --- /dev/null +++ b/More Operators/Regular Expressions/EXERCISE_REGEXP2.sql @@ -0,0 +1,3 @@ +SELECT * +FROM customers +WHERE last_name REGEXP 'ey$|on$' \ No newline at end of file diff --git a/More Operators/Regular Expressions/EXERCISE_REGEXP3.sql b/More Operators/Regular Expressions/EXERCISE_REGEXP3.sql new file mode 100644 index 0000000..7885642 --- /dev/null +++ b/More Operators/Regular Expressions/EXERCISE_REGEXP3.sql @@ -0,0 +1,3 @@ +SELECT * +FROM customers +WHERE last_name REGEXP '^my|se' \ No newline at end of file diff --git a/More Operators/Regular Expressions/EXERCISE_REGEXP4.sql b/More Operators/Regular Expressions/EXERCISE_REGEXP4.sql new file mode 100644 index 0000000..571a6af --- /dev/null +++ b/More Operators/Regular Expressions/EXERCISE_REGEXP4.sql @@ -0,0 +1,3 @@ +SELECT * +FROM customers +WHERE last_name REGEXP 'b[ru]' \ No newline at end of file diff --git a/More Operators/Regular Expressions/mySQL_REGEXP.sql b/More Operators/Regular Expressions/mySQL_REGEXP.sql new file mode 100644 index 0000000..d4e411a --- /dev/null +++ b/More Operators/Regular Expressions/mySQL_REGEXP.sql @@ -0,0 +1,13 @@ +SELECT * +FROM customers +-- WHERE last_name REGEXP 'field' +-- WHERE last_name REGEXP '^field' <- this must START with field +-- WHERE last_name REGEXP 'field$' <- this must END with field +/* WHERE last_name REGEXP 'field$|mac|rose' /* <- same as a "IN" statement.. + you can apply to the same techniques above */ +/* WHERE last_name REGEXP '[gim]e' /* This statement takes an expression and returns anything + that is ge, ie, or me in their last name */ +/* WHERE last_name REGEXP 'e[fmq]' /* Same thing as line 8, but at the end of e */ +WHERE last_name REGEXP '[a-h]e' /* Same thing as line 10, but at gets anything from a through h */ +/* mySQL has more of these expressions, but these are the ones that you +will be using 90% of the time. diff --git a/More Operators/mySQL_LIMIT.sql b/More Operators/mySQL_LIMIT.sql new file mode 100644 index 0000000..c4eb9f8 --- /dev/null +++ b/More Operators/mySQL_LIMIT.sql @@ -0,0 +1,3 @@ +SELECT * +FROM customers +LIMIT 6, 3 -- start at 6, then get the next 3 (7,8,9) diff --git a/More Operators/mySQL_OPERATORS_BETWEEN.sql b/More Operators/mySQL_OPERATORS_BETWEEN.sql new file mode 100644 index 0000000..21a6a94 --- /dev/null +++ b/More Operators/mySQL_OPERATORS_BETWEEN.sql @@ -0,0 +1,5 @@ +SELECT * +FROM customers +-- WHERE points >= 1000 AND points <= 3000 +-- simplier way: +WHERE points BETWEEN 1000 AND 3000 \ No newline at end of file diff --git a/More Operators/mySQL_OPERATORS_IN.sql b/More Operators/mySQL_OPERATORS_IN.sql new file mode 100644 index 0000000..fe5a266 --- /dev/null +++ b/More Operators/mySQL_OPERATORS_IN.sql @@ -0,0 +1,8 @@ +SELECT * +FROM customers +-- WHERE state = 'VA' OR state = 'GA' OR state = 'FL' +-- SIMPLIER WAY: +WHERE state IN ('VA', 'GA', 'FL') +-- YOU CAN ALSO DO IT WITH NOT STATEMENTS +-- WHERE state NOT IN ('VA', 'GA', 'FL') + diff --git a/More Operators/mySQL_OPERATORS_LIKE.sql b/More Operators/mySQL_OPERATORS_LIKE.sql new file mode 100644 index 0000000..166d569 --- /dev/null +++ b/More Operators/mySQL_OPERATORS_LIKE.sql @@ -0,0 +1,7 @@ +SELECT * +FROM customers +WHERE last_name LIKE 'b%' + +/* Note: +Use % to represent any number of characters +Use _ to represent a single character */ diff --git a/More Operators/mySQL_ORDERBY.sql b/More Operators/mySQL_ORDERBY.sql new file mode 100644 index 0000000..3669d3c --- /dev/null +++ b/More Operators/mySQL_ORDERBY.sql @@ -0,0 +1,9 @@ +SELECT /***/ first_name, last_name, 10 AS points +FROM customers +-- ORDER BY first_name /* You can use DESC for decending */ +-- ORDER BY state, first_name +-- ORDER by birth_date +ORDER BY 1,2 + +/* AVOID THIS FOR NOW... TRY AND LOOK BACK IN THE FUTURE. */ + diff --git a/EXERCISE3_OPERATORS.sql b/Operators/EXERCISE3_OPERATORS.sql similarity index 100% rename from EXERCISE3_OPERATORS.sql rename to Operators/EXERCISE3_OPERATORS.sql diff --git a/mySQL_OPERATORS_AND.sql b/Operators/mySQL_OPERATORS_AND.sql similarity index 100% rename from mySQL_OPERATORS_AND.sql rename to Operators/mySQL_OPERATORS_AND.sql diff --git a/mySQL_OPERATORS_AND_OR.sql b/Operators/mySQL_OPERATORS_AND_OR.sql similarity index 100% rename from mySQL_OPERATORS_AND_OR.sql rename to Operators/mySQL_OPERATORS_AND_OR.sql diff --git a/mySQL_OPERATORS_NOT.sql b/Operators/mySQL_OPERATORS_NOT.sql similarity index 100% rename from mySQL_OPERATORS_NOT.sql rename to Operators/mySQL_OPERATORS_NOT.sql diff --git a/mySQL_OPERATORS_OR.sql b/Operators/mySQL_OPERATORS_OR.sql similarity index 100% rename from mySQL_OPERATORS_OR.sql rename to Operators/mySQL_OPERATORS_OR.sql diff --git a/EXERCISE1_SELECTCLAUSE.sql b/Select/EXERCISE1.sql similarity index 100% rename from EXERCISE1_SELECTCLAUSE.sql rename to Select/EXERCISE1.sql diff --git a/mySQL_SELECT.sql b/Select/mySQL_SELECT.sql similarity index 100% rename from mySQL_SELECT.sql rename to Select/mySQL_SELECT.sql diff --git a/mySQL_SELECTCLAUSE.sql b/Select/mySQL_SELECTCLAUSE.sql similarity index 100% rename from mySQL_SELECTCLAUSE.sql rename to Select/mySQL_SELECTCLAUSE.sql diff --git a/EXERCISE2_WHERE.sql b/Where/EXERCISE2_WHERE.sql similarity index 100% rename from EXERCISE2_WHERE.sql rename to Where/EXERCISE2_WHERE.sql diff --git a/mySQL_WHERE.sql b/Where/mySQL_WHERE.sql similarity index 100% rename from mySQL_WHERE.sql rename to Where/mySQL_WHERE.sql