0% found this document useful (0 votes)
20 views22 pages

Basic Queries

The document provides an overview of SQL (Structured Query Language) and its use in accessing and manipulating databases, including various tables such as Customers, Products, Orders, and Employees. It includes examples of SQL queries for selecting, sorting, and filtering data, as well as explanations of the WHERE clause and logical operators. Additionally, it offers links for further resources on installing and connecting to MySQL.

Uploaded by

Mạnh Hồ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views22 pages

Basic Queries

The document provides an overview of SQL (Structured Query Language) and its use in accessing and manipulating databases, including various tables such as Customers, Products, Orders, and Employees. It includes examples of SQL queries for selecting, sorting, and filtering data, as well as explanations of the WHERE clause and logical operators. Additionally, it offers links for further resources on installing and connecting to MySQL.

Uploaded by

Mạnh Hồ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 22

 SQL stands for Structured Query Language

 SQL lets you access and manipulate


databases
• Customers: stores customer’s data.
• Products: stores a list of scale model cars.
• ProductLines: stores a list of product line categories.
• Orders: stores sales orders placed by customers.
• OrderDetails: stores sales order line items for each
sales order.
• Payments: stores payments made by customers
based on their accounts.
• Employees: stores all employee information as well as
the organization structure such as who reports to
whom.
• Offices: stores sales office data.
 https://www.mysqltutorial.org/install-mysql
/
 https://www.mysqltutorial.org/getting-
started-with-mysql/connect-to-mysql-
server/
 Querying data: SELECT
 Sorting data: ORDER BY
 Filtering data: WHERE, AND, OR, IN,
BETWEEN, LIKE, IS NULL
SELECT lastname, firstname, jobtitle
FROM employees;
 SELECT statement to retrieve data
from all columns example
SELECT *
FROM employees;
SELECT contactLastname,
contactFirstname
FROM customers
ORDER BY contactLastname;
SELECT select_list
FROM table_name
ORDER BY column1 [ASC|DESC],
column2 [ASC|DESC], ...;
SELECT contactLastname, contactFirstname
FROM customers
ORDER BY contactLastname,
contactFirstname;
SELECT orderNumber, orderLineNumber,
quantityOrdered * priceEach AS subtotal
FROM orderdetails
ORDER BY subtotal DESC;
 WHERE clause allows you to specify a search
condition for the rows returned by a query
SELECT select_list
FROM table_name
WHERE search_condition;
 The search_condition is a combination of one or
more predicates using the logical operator AND,
OR and NOT
 In the SELECT statement, the WHERE
clause is evaluated after the FROM clause
and before the SELECT clause.
SELECT lastname, firstname, jobtitle
FROM employees
WHERE jobtitle = 'Sales Rep';
 SELECT lastname, firstname,
jobtitle, officeCode
FROM employees
WHERE jobtitle = 'Sales Rep' AND
officeCode = 1;
Operator Description
= Equal to. You can use it with almost any data
types.
<> or != Not equal to
< Less than. You typically use it with numeric and
date/time data types.
> Greater than.
<= Less than or equal to
>= Greater than or equal to
 SELECT firstName, lastName, officeCode
FROM employees
WHERE officeCode IN (1 , 2, 3)
ORDER BY officeCode;
SELECT firstName, lastName
FROM employees
WHERE lastName LIKE '%son’
ORDER BY firstName;
SELECT lastName, firstName, reportsTo
FROM employees
WHERE reportsTo IS NULL;

You might also like