SQLnotes
SQLnotes
What is SQL?
- SQL stands for Structured Query Language
- SQL lets you access and manipulate databases
- SQL became a standard of the American National Standards
Institute (ANSI) in 1986, and of the International Organization for
Standardization (ISO) in 1987
RDBMS:
RDBMS stands for Relational Database Management System.
RDBMS is the basis for SQL, and for all modern database systems such as
MS SQL Server, IBM DB2, Oracle, MySQL, and Microsoft Access.
The data in RDBMS is stored in database objects called tables. A table is
a collection of related data entries and it consists of columns and rows.
Database Tables:
-A database most often contains one or more tables. Each table is identified by
a name (e.g. "Customers" or "Orders"), and contain records (rows) with data.
SQL keywords are NOT case sensitive: select is the same as SELECT.
-Some database systems require a semicolon at the end of each SQL statement.
Semicolon is the standard way to separate each SQL statement in database
systems that allow more than one SQL statement to be executed .
Syntax
SELECT column1, column2, ...
FROM table_name;
Syntax
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.
Example
SELECT COUNT(DISTINCT Country) FROM Customers;
Note: The COUNT(DISTINCT column_name) is not supported in Microsoft
Access databases.
Here is a workaround for MS Access:
Example
SELECT Count(*) AS DistinctCountries
FROM (SELECT DISTINCT Country FROM Customers);