What Is SQL
What Is SQL
What is sql:
2.
SELECT column_name,column_name
FROM table_name;
and
SELECT * FROM table_name;
3.
In a table, a column may contain many duplicate values; and sometimes you only want to list the different
(distinct) values.The DISTINCT keyword can be used to return only distinct (different) values.
SQL SELECT DISTINCT Syntax:
The WHERE clause is used to extract only those records that fulfill a specified criterion.
SQL WHERE Syntax:
SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
e.g: SELECT * FROM Customers ->Gives complete table having mexico city only.
WHERE Country='Mexico';
Operators in The WHERE Clause:
Description
Equal
<>
Not equal. Note: In some versions of SQL this operator may be written as !=
>
Greater than
<
Less than
>=
<=
BETWEEN
LIKE
IN
5.
The following SQL statement selects all customers from the country "Germany" AND the city
"Berlin", in the "Customers" table:
The following SQL statement selects all customers from the city "Berlin" OR "Mnchen", in the
"Customers" table:
The following SQL statement selects all customers from the country "Germany" AND the city must be
equal to "Berlin" OR "Mnchen", in the "Customers" table:
The ORDER BY keyword is used to sort the result-set by one or more columns.The ORDER BY keyword sorts the
records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword.
The following SQL statement selects all customers from the "Customers" table,
sorted by the "Country" column:
e.g:SELECT * FROM Customers ORDER BY Country;
The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by
the "Country" column:
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country"
and the "CustomerName" column:
Assume we wish to update the customer "Alfreds Futterkiste" with a new contact person and city.We use
the following SQL statement:
e.g:UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
Be careful when updating records. If we had omitted the WHERE clause, in the example above, like this:
e.g:UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg';
9.
Assume we wish to delete the customer "Alfreds Futterkiste" from the "Customers" table.We use the
following SQL statement:
It is possible to delete all rows in a table without deleting the table. This means that the table structure,
attributes, and indexes will be intact: