An Introduction to SQL | SQL Tutorials

Home >> An Introduction to SQL

An Introduction to SQL

PDF

Introduction

SQL is a standard computer language for accessing and manipulating databases.

Tables

A database often contains one or more tables (relational databases). Each table is identified by a name (eg sales_company or sales_contacts). Tables contain records (rows) with data. Tables in relational databases are linked together using common ids, for example, companyid or contactid.

Data Types

There are many data types in SQL. These can be summarized as:

SQL Queries

With SQL, we can query a database and have a result set returned.

A query like this:

SELECT company_name FROM sales_company

Gives a result set like this:

Company Name
Absolutx
Addidas
All Blacks
Alpha Telecom

Simple Examples

Q1) List all companies, by name, in the CRM database

SELECT company_name FROM sales_company

Q2) List all companies and their creation date

SELECT company_name, date_created FROM sales_company

Q3) List all columns from the sales_company table

SELECT * FROM sales_company

WHERE Examples

Q4) List all companies in the CRM database where the meshowner is Anna.Murray

SELECT company_name FROM sales_company WHERE meshowner='Anna.Murray'

Q5) List the last name of all contacts in the CRM database whose first name is John.

SELECT last_name FROM sales_contacts WHERE first_name='John'

Q6) List all companies created after 1/08/04

SELECT company_name FROM sales_company WHERE date_created > '20040801'

Multiple WHERE Examples

Q7) List the email addresses of all contacts whose first name is Dominic and last name is Marsat

SELECT email FROM sales_contacts WHERE first_name='Dominic' AND last_name='Marsat'

Q8) List all history comments created by Anna Murray after 15/09/04

SELECT history FROM sales_history WHERE usermesh='Anna.Murray' AND date_created > '20040915'


Partners: Hearing Aid Talk Forum for Hearing Aids | One Direction Forum | Adult Toys

© Pixel Kicks, 5 Marlborough Road, Royton, Oldham, OL2 6AU.