






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
If you want to learn everything SQL has to offer and become a SQL expert, check out my Complete SQL Mastery Course. Use the coupon code CHEATSHEET upon checkout ...
Typology: Summaries
1 / 11
This page cannot be seen from the preview
Don't miss anything!







Basics USE sql_store; SELECT * FROM customers WHERE state = ‘CA’ ORDER BY first_name LIMIT 3;
—- This is a comment and it won’t get executed. SELECT Clause —- Using expressions SELECT (points * 10 + 20) AS discount_factor FROM customers
IN Operator —- Returns customers in any of these states: VA, NY, CA SELECT * FROM customers WHERE state IN (‘VA’, ‘NY’, ‘CA’) BETWEEN Operator SELECT * FROM customers WHERE points BETWEEN 100 AND 200 LIKE Operator —- Returns customers whose first name starts with b SELECT * FROM customers WHERE first_name LIKE ‘b%’
More Examples —- Returns customers whose first name ends with EY or ON WHERE first_name REGEXP ‘ey$|on$’ —- Returns customers whose first name starts with MY —- or contains SE WHERE first_name REGEXP ‘^my|se’ —- Returns customers whose first name contains B followed by —- R or U WHERE first_name REGEXP ‘b[ru]’ IS NULL Operator —- Returns customers who don’t have a phone number SELECT * FROM customers WHERE phone IS NULL ORDER BY Clause —- Sort customers by state (in ascending order), and then —- by their first name (in descending order) SELECT * FROM customers ORDER BY state, first_name DESC LIMIT Clause —- Return only 3 customers SELECT * FROM customers LIMIT 3
Unions —- Combine records from multiple result sets SELECT name, address FROM customers UNION SELECT name, address FROM clients Inserting Data —- Insert a single record INSERT INTO customers(first_name, phone, points) VALUES (‘Mosh’, NULL, DEFAULT) —- Insert multiple single records INSERT INTO customers(first_name, phone, points) VALUES (‘Mosh’, NULL, DEFAULT), (‘Bob’, ‘1234’, 10) Want to Become a SQL Expert?