Home > Articles

  • Print
  • + Share This
This chapter is from the book

Introduction to SQL

The Structured Query Language, known as SQL, is the language used to talk to most databases. All the previously mentioned databases understand this language, which allows you to talk to them. SQL is a very powerful language and can be a little complicated the further you dive into it. But for now, you only need to know a few frequently used commands.

TABLE 1–2 SQL Basics

Keyword

Definition and Usage

SELECT

Used to select data from the database

Usage

SELECT * FROM table

Note: The (*) selects all fields in the specified table.

INSERT

Used to insert new information into the database

Usage

INSERT INTO table (field1,field2) Values ('Micah','Mike')

DELETE

Used to delete data from a database

Usage

DELETE FROM table
WHERE name = 'Mike'

UPDATE

Used to update data in the database

Usage

UPDATE table
SET Name1 = 'Mike', Name2 = 'Micah'

TABLE 1–3 SQL Basics—Attributes

Keyword

Definition and Usage

WHERE

Used to select a certain record

Usage

SELECT *
FROM table
WHERE name = 'Micah'

ASC

Used to sort results in ascending order

Usage

SELECT *
FROM table

WHERE name = 'Micah' ASC

DESC

Used to sort results in descending order

Usage

SELECT *
FROM table
WHERE name = 'Mike' DESC

ORDER BY

Used to sort results by a field name

Usage

SELECT *
FROM table
ORDER BY name

DISTINCT

Used to list distinct field names. If multiple names appear in a field column, only one is returned.

Usage

SELECT DISTINCT category
FROM table

LIKE

Used to search a field for certain text

Usage

SELECT *
FROM table
WHERE name LIKE '%Mike%' 

Note: The "%" is a wildcard character that returns all records containing the string 'Mike'.

AND

Condition used to ensure two or more fields of information hold true

Usage

SELECT *
FROM table
WHERE fName = 'Mike' AND lName = 'Fredrick'

OR

Condition used to ensure that any of the two or more fields of information holds true

Usage

SELECT *
FROM table
WHERE fName = 'Mike' OR fName = 'Micah'

BETWEEN

Condition used to return a result within a certain range

Usage

SELECT *
FROM table
WHERE birthDate BETWEEN '01' AND '10'

IN

Condition used to return any specified results in a field

Usage

SELECT *
FROM table
WHERE birthDate IN ('01','10','23')

=

Equal to operator, used to find exact matches; mostly used with WHERE clause

<>

Not equal to operator, used to return results that do not equal; used with the WHERE clause

>

Greater than operator

>=

Greater than or equal to operator

<

Less than operator

<=

Less than or equal to operator


  • + Share This
  • 🔖 Save To Your Account