SQL is a tool for organizing, managing, and retrieving data stored by a computer database. The acronym SQL is an abbreviation for Structured Query Language. For historical reasons, SQL is usually pronounced "sequel," but the alternate pronunciation "S.Q.L." is also used. As the name implies, SQL is a computer language that you use to interact with a database. In fact, SQL works with one specific type of database, called a relational database.
What is Table ?
A relational database system contains one or more objects called tables. The data or information for the database are stored in these tables. Tables are uniquely identified by their names and are comprised of columns and rows. Columns contain the column name, data type, and any other attributes for the column. Rows contain the records or data for the columns. Here is a sample table called "student".
SQL Queries :
+ Selecting Data:
The SQL SELECT statement queries data from tables in the database. The statement begins with the SELECT keyword. The basic SELECT statement has 3 clauses:
+ SELECT
+ FROM
+ WHERE
The SELECT clause specifies the table columns that are retrieved. The FROM clause specifies the tables accessed. The WHERE clause specifies which table rows are used. The WHERE clause is optional; if missing, all table rows are used.
Example SELECT statement :
Select LName From Customer
Example SELECT with WHERE :
Select LName From Customer where ciy='Roma'
Conditional selections used in the where clause:
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal to
LIKE *See note below
The LIKE pattern matching operator can also be used in the conditional selection of the where clause. Like is a very powerful operator that allows you to select only rows that are "like" what you specify. The percent sign "%" can be used as a wild card to match any possible character that might appear before or after the characters specified.
Example :
select first, last, city
from empinfo
where first LIKE 'Gin%';
This SQL statement will match any first names that start with 'Gin'. Strings must be in single quotes.
Or you can specify,
select first, last
from empinfo
where last LIKE '%s'; This statement will match any last names that end in a 's'.
select * from empinfo
where first = 'Ginger'; This will only select rows where the first name equals 'Ginger' exactly.
Example : you have table with information :
Run command :
select first, last, city
from empinfo
where first LIKE 'Gin%';