SQL - IN Operator Example
The following SQL statement selects all customers with a City of "Paris" or "London":
SQL - LIKE Operator Examples
The following SQL statement selects all customers with a City starting with the letter "s":
Tip: The "%" sign is used to define wildcards (missing letters) both before and after the pattern. You will learn more about wildcards in the next chapter.
The following SQL statement selects all customers with a City ending with the letter "s":
The following SQL statement selects all customers with a Country containing the pattern "land":
Using the NOT keyword allows you to select records that do NOT match the pattern.
The following SQL statement selects all customers with Country NOT containing the pattern "land":
SQL - Delete All Data
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:
DELETE FROM table_name;
or
DELETE * FROM table_name;
Note: Be very careful when deleting records. You cannot undo this statement!
SQL - DELETE Example
Assume we wish to delete the customer "Alfreds Futterkiste" from the "Customers" table.
We use the following SQL statement:
Example
DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
Try it Yourself »SQL - Update Warning!
Be careful when updating records. If we omit the WHERE clause, ALL records will be updated:
SQL - UPDATE Multiple Records
In an update statement, it is the WHERE clause that determines how many records which will be updated.
The WHERE clause:
WHERE Country='Mexico'
will update all records which have the value "Mexico" in the field "Country".SQL - UPDATE Multiple Columns
To update more than one column, use a comma as seperator.
Assume we wish to update the customer "Alfreds Futterkiste" with a new contact person and city.
We use the following SQL statement:
Example
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Frankfurt'
WHERE CustomerID=1;
Try it Yourself »SQL - ORDER BY Several Columns Example 2
The following SQL statement selects all customers from the "Customers" table, sorted ascending by the "Country" and descending by the "CustomerName" column:
SQL - ORDER BY Several Columns Example
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" and the "CustomerName" column:
SQL - ORDER BY DESC Example
The following SQL statement selects all customers from the "Customers" table, sorted DESCENDING by the "Country" column:
SQL - ORDER BY Example
The following SQL statement selects all customers from the "Customers" table, sorted by the "Country" column:
SQL - Combining AND & OR
You can also combine AND and OR (use parenthesis to form complex expressions).
The following SQL statement selects all customers from the country "Germany" AND the city must be equal to "Berlin" OR "Mรผnchen", in the "Customers" table:
Example
SELECT * FROM Customers
WHERE Country='Germany'
AND (City='Berlin' OR City='Mรผnchen');
Try it Yourself »SQL - OR Operator Example
The following SQL statement selects all customers from the city "Berlin" OR
"Mรผnchen", in the "Customers" table:
SQL - AND Operator Example
The following SQL statement selects all customers from the country "Germany" AND the city "Berlin", in the "Customers" table:
SQL - Operators in The WHERE Clause
The following operators can be used in the WHERE clause:
Operator | Description |
---|---|
= | Equal |
<> | Not equal. |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
BETWEEN | Between an inclusive range |
LIKE | Search for a pattern |
IN | To specify multiple possible values for a column |
SQL - Text Fields vs. Numeric Fields
SQL requires single quotes around text values (most database systems will also allow double quotes).
However, numeric fields should not be enclosed in quotes:
SQL - WHERE Clause Example
The following SQL statement selects all the customers from the country "Mexico", in the "Customers" table:
SQL - SELECT DISTINCT Example
The following SQL statement selects only the distinct values from the "City" columns from the "Customers" table:
SQL - SELECT * Example
The following SQL statement selects all the columns from the "Customers" table:
SQL - SELECT Column Example
The following SQL statement selects the "CustomerName" and "City" columns from the "Customers" table:
SQL - Comments in Statements
To ignore just a part of a statement, use the /* */ comment.
Any text between /* and */ will be ignored.
Example
Ignore part of a line:
SELECT CustomerName, /*City,*/ Country FROM Customers;
Try it Yourself »Example
Ignore a parts of a statment:
SELECT * FROM Customers WHERE (CustomerName LIKE 'L%'
OR CustomerName LIKE 'R%' /*OR CustomerName LIKE 'S%'
OR CustomerName LIKE 'T%'*/ OR CustomerName LIKE 'W%')
AND Country='USA'
ORDER BY CustomerName;
Try it Yourself »SQL - Multi-line Comments
Multi-line comments start with /* and end with */.
Any text between /* and */ will be ignored.
Example
A multi-line comment as an explanation:
/*Select all the columns
of all the records
in the Customers table:*/
SELECT * FROM Customers;
Try it Yourself »Example
A multi-line comment to ignore many statements:
/*SELECT * FROM Customers;
SELECT * FROM Products;
SELECT * FROM Orders;
SELECT * FROM Categories;*/
SELECT * FROM Suppliers;
Try it Yourself »SQL - Single Line Comments
Single line comments start with --.
Any line between -- and the end of the line will be ignored (will not be executed).
Example
A single-line comment as an explanation:
--Select all:SELECT * FROM Customers;
Try it Yourself »Example
A single-line comment to ignore the end of a line:
SELECT * FROM Customers -- WHERE City='Berlin';
Try it Yourself »Example
A single-line comment to ignore a statement:
--SELECT * FROM Customers;SELECT * FROM Products;
Try it Yourself »Some of The Most Important SQL Commands
- SELECT - extracts data from a database
- UPDATE - updates data in a database
- DELETE - deletes data from a database
- INSERT INTO - inserts new data into a database
- CREATE DATABASE - creates a new database
- ALTER DATABASE - modifies a database
- CREATE TABLE - creates a new table
- ALTER TABLE - modifies a table
- DROP TABLE - deletes a table
- CREATE INDEX - creates an index (search key)
- DROP INDEX - deletes an index
HTML Form - The Submit Button
<input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a server page with a script for processing input data.
The form-handler is specified in the form's action attribute:
Example
<form action="action_page.php">
First name:<br>
<input type="text" name="firstname" value="Mickey"><br>
Last name:<br>
<input type="text" name="lastname" value="Mouse"><br><br>
<input type="submit" value="Submit">
</form>
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
HTML Form - Radio Button Input
<input type="radio"> defines a radio button.
Radio buttons let a user select ONE of a limited number of choices:
Example
<form>
<input type="radio" name="gender" value="male" checked> Male<br>
<input type="radio" name="gender" value="female"> Female<br>
<input type="radio" name="gender" value="other"> Other
</form>
Try it Yourself »
This is how the HTML code above will be displayed in a browser:
MaleFemale
Other
Following tips
Friends please follow my blog to get direct updates in your mailbox.
Get direct mail to you about new posts and updates.
Thanking You
Abhishek Gupta
HTML Form - Text Input
<input type="text"> defines a one-line input field for text input:
Example
<form>
First name:<br>
<input type="text" name="firstname"><br>
Last name:<br>
<input type="text" name="lastname">
</form>
Try it Yourself »
This is how it will look like in a browser:
First name:Last name:
Note: The form itself is not visible. Also note that the default width of a text field is 20 characters.
Subscribe to:
Posts (Atom)