SQL Tutorial Flashcards
(121 cards)
SQL
Structured Query Language
RDBMS
Relational Database Management System
How is the data in RDBMS stored?
The data in RDBMS is stored in database objects called tables.
Table
A table is a collection of related data entries and it consists of columns and rows.
Fields / Columns
A field is a column in a table that is designed to maintain specific information about every record in the table.
A column is a vertical entity in a table that contains all information associated with a specific field in a table.
Record and/or Row
A record is a horizontal entity in a table.
Select
The SELECT statement is used to select data from a database.
Syntax
SELECT column1, column2, …
FROM table_name;
Select All
If you want to return all columns, without specifying every column name, you can use the SELECT * syntax:
SELECT * FROM Customers;
The SQL SELECT DISTINCT Statement
The SELECT DISTINCT statement is used to return only distinct (different) values.
SELECT DISTINCT column1, column2, …
FROM table_name;
Count Distinct
By using the DISTINCT keyword in a function called COUNT, we can return the number of different countries.
SELECT Count(*) AS DistinctCountries
FROM (SELECT DISTINCT Country FROM Customers);
The SQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
SELECT *
FROM Customers
WHERE Country=’Mexico’;
Operators in The WHERE Clause
= , > , < , >= , <= , <> , BETWEEN , LIKE , IN
=
Equal
>
Greater than
<
Less than
> =
Greater than or equal
<=
Less than or equal
<>
Not equal
!=
Not equal
BETWEEN
between a certain range
LIKE
search for a pattern
IN
To Specify multiple possible values for a column
ORDER BY
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;
ORDER BY Several Columns
SELECT * FROM Customers
ORDER BY Country, CustomerName;